[英]Rails Jquery upload file using remotipart gem NoMethodError: undefined method `name'
I am using gem remotipart for uploading file. 我正在使用gem remotipart上传文件。 Here is my view:
这是我的看法:
<%= form_for @file_upload, :id => "form_feedback_attachment", :url => { :controller => "widgets", :action => "feedback_attachment_upload" }, :html => {:multipart => true} do |f| %>
<td class="rightcol"><%= f.file_field :feedback_attachment, :id => "feedback_attachment_file" %>
<%= f.submit "Upload" %></td>
<% end %>
My controller: 我的控制器:
@file_upload = FileUpload.new
@file_upload.feedback_attachment = params[:file_upload][:feedback_attachment]
respond_to do |format|
if @file_upload.save
format.js
end
end
But I get this error : NoMethodError: undefined method `name' for nil:NilClass. 但是我得到了这个错误:NoMethodError:nil:NilClass的未定义方法“名称”。 I have no idea from where is the method name and from which Class.
我不知道从哪里来的方法名称和从哪个类。 Any help would be really appreciated.
任何帮助将非常感激。 Thanks
谢谢
At first glance - you have not set :remote => true, which is necessary for the form to work with ajax, so it should be: 乍一看-您尚未设置:remote => true,这对于使用ajax的表单是必需的,因此应为:
<%= form_for @file_upload, :remote => true, :id => "form_feedback_attachment", :url => { :controller => "widgets", :action => "feedback_attachment_upload" }, :html => {:multipart => true} do |f| %>
At the controller, if you are using this action for something else this may be a problem, so you should wrap it like this: 在控制器上,如果您将此动作用于其他用途,则可能会出现问题,因此应像这样包装它:
if @file_upload
@file_upload.feedback_attachment = params[:file_upload][:feedback_attachment]
respond_to do |format|
if @file_upload.save
format.js
end
end
end
Also note that i have removed the first line. 另请注意,我已经删除了第一行。 Hope this helps.
希望这可以帮助。 {:
{:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.