<%= semantic_form_for(@image, :url => { :action => "create_friend_upload" }, :html => {:multipart => true}) do |f| %>
<%= f.inputs do %>
<%= f.input :image, :input_html => {:multiple => true}, name: "gallery[image]" %>
<%= f.hidden_field :friend_upload, :value => true %>
<%= f.hidden_field :user_id %>
<%= f.hidden_field :friend_uploader, :value => current_user.name %>
<% end %>
<%= f.buttons do %>
<%= f.commit_button :button_html => {:class => "primary"} %>
<% end %>
<% end %>
我的问题是它不断提交一个数组,这是 Carrierwave 无法处理的。它一直显示 name=\"gallery[image][]\"
而不仅仅是 name=\"gallery[image]\"
。 (见下文)。因此,我还不断收到错误消息 can't conversion nil into String
。
@headers="Content-Disposition: form-data; name=\"gallery[image][]\"; filename=\"VW 3.jpeg\"\r\nContent-Type: image/jpeg\r\n",
有人知道怎么解决这个问题吗?谢谢!
更新:
我也确实在 JQuery 上看过 Ryan 的 Railscasts 视频,他对此的修复对我来说不起作用。
画廊.rb
class Gallery < ActiveRecord::Base
attr_accessible :image, :name, :friend_upload,
mount_uploader :image, GalleryUploader
end
图库 Controller
def friend_upload
@image = Gallery.new
end
def create_friend_upload
@image = Gallery.create(params[:gallery])
end
最佳答案
因为您指定了 :multiple => true
,rails 会生成 name="gallery[image][]"
。由于https://github.com/rails/rails/pull/8108,您在升级到最新版本的rails (3.2.13) 时也可能会遇到此问题。 。
简单的修复方法类似于
$('#fileupload').fileupload({
paramName: 'gallery[image]'
});
这利用paramName
选项来指定文件表单数据
引用文献:
关于jquery - 使用 Carrierwave 和 JQuery 文件上传进行多个文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12806230/