[英]Multiple File Upload using Carrierwave and JQuery File Upload
<%= 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 convert 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視頻,他對此的修復對我不起作用。
Gallery.rb
class Gallery < ActiveRecord::Base
attr_accessible :image, :name, :friend_upload,
mount_uploader :image, GalleryUploader
end
畫廊控制器
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
選項指定文件表單數據
參考文獻:
問題出現是因為你沒有把name
放在input_html
,這就是使用simple form
和可能是semantic form
的東西
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.