我正在使用dropzone-rails添加dropzone到我的 Rails 应用程序。我使用 CarrierWave 进行图像上传,无需 Dropzone 即可正常工作。
当我将图像拖放到拖放区表单时,出现错误。该表单位于我的“Canvas”模型的编辑页面上。
表单 html
<%= form_for(@canvas, :html => { :class => 'dropzone', :id => 'awesomeDropzone' }) do |f| %>
<%= f.file_field :image %>
<%= f.submit %>
<% end %>
Dropzone JS 调用
Dropzone.options.awesomeDropzone = {
paramName: "canvas[image]", // The name that will be used to transfer the file
clickable: false
};
控制台错误:
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
最佳答案
根据错误,
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"
):
您没有edit
查看 canvases
。确保您有edit.html.erb
文件在 app/views/canvases
文件夹。
更新
此外,我注意到该请求是针对 Processing by CanvasesController#edit as JSON
,
注意格式为JSON
而不是HTML
。如果您有edit.html.erb
文件并且您想要呈现该特定 View ,请确保在调用 edit
时未将格式指定为“JSON”操作,因此默认格式将被视为 HTML
.
更改您的 update
操作如下:
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
关于javascript - Dropzone Rails 505 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23281265/