0
votes

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

2
Turn on debugging (config.consider_all_requests_local = true) and look at the actual error and stack trace. - coreyward
How do I turn on debugging? What do I do with that line of code you wrote? - colmtuite
If you're running your rails application with RAILS_ENV set to development, this is the default, and you'll see an error and stack trace output. If you're running in a different environment (specifically, production), by default you won't see errors. You can either adjust the setting in the relevant config/environments/____.rb file or change the environment you're booting in. Since this is localhost, you probably just want to run in development mode. - coreyward
You should have the full trace in your logs; by default, that's at ./log/#{environment}.log. - coreyward
I updated the question with a link to the logs....I think. - colmtuite

2 Answers

2
votes

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
0
votes

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

render nothing: true

or

render nothing: true, status: 200

Regards!