Question

I'm using dropzone-rails to add dropzone to my Rails app. I'm using CarrierWave for image uploads which is working fine without Dropzone.

I'm getting an error when I drop an image onto my dropzone form. The form is located on the edit page of my "Canvas" model.

Form html

<%= form_for(@canvas, :html => { :class => 'dropzone', :id => 'awesomeDropzone' }) do |f| %>
  <%= f.file_field :image %>
  <%= f.submit %>
<% end %>

Dropzone JS call

Dropzone.options.awesomeDropzone = {
  paramName: "canvas[image]", // The name that will be used to transfer the file
  clickable: false
};

Console error:

GET http://localhost:3000/canvases/21/edit 500 (Internal Server Error)

canvases_controller.rb

def edit
    @canvas = Canvas.find(params[:id])
end

def update
  @canvas = Canvas.find(params[:id])

  if @canvas.update_attributes(update_params)
    redirect_to edit_canvas_path(@canvas)
  else
    render :edit
  end
end

canvas.rb

mount_uploader :image, ImageUploader

Full log data

Was it helpful?

Solution

As per the error,

ActionView::MissingTemplate (Missing template canvases/edit, application/edit with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
  * "/Users/colmtuite/dev/design_tool/app/views"
):

You don't have edit view for canvases. Make sure that you have edit.html.erb file in app/views/canvases folder.

UPDATE

Also, I noticed that the request is going for Processing by CanvasesController#edit as JSON, NOTE the format is JSON and not HTML. If you have edit.html.erb file and you want to render that particular view, make sure that you don't specify format as 'JSON' while calling edit action so by default format would be considered as HTML.

Change your update action as below:

def update
  @canvas = Canvas.find(params[:id])

  if @canvas.update_attributes(update_params)
    redirect_to edit_canvas_path(@canvas, format: :html) ## Specify format as html
  else
    render :edit
  end
end

OTHER TIPS

dropzone using JSON format, not HTML, so you can change controller to:

render nothing: true

or

render nothing: true, status: 200

Regards!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top