lundi 29 août 2016

Ruby on Rails - AbstractController::DoubleRenderError

i try to add to my create-method one redirect to my support tickets. But always i get an

AbstractController::DoubleRenderError

But i need this redirect after the upload of the file. How can i fix this ?

Upload-controller :

def create

   @upload = Upload.new(params[:upload])

      respond_to do |format|
          if @upload.save
           format.html {
             render :json => [@upload.to_jq_upload].to_json,
             :content_type => 'text/html',
             :layout => false
           }

           format.json { render json: {files: [@upload.to_jq_upload]}, status: :created, location: @upload }

        else
           format.html { render action: "new" }
           format.json { render json: @upload.errors, status: :unprocessable_entity }
        end
        redirect_to new_support_ticket_path
     end
end

upload.rb :

class Upload < ActiveRecord::Base
  attr_accessible :upload
  has_attached_file :upload

  include Rails.application.routes.url_helpers

  def to_jq_upload
    {
      "name" => read_attribute(:upload_file_name),
      "size" => read_attribute(:upload_file_size),
      "url" => upload.url(:original),
      "delete_url" => upload_path(self),
      "delete_type" => "DELETE" 
    }

  end

end

Aucun commentaire:

Enregistrer un commentaire