<%= 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 视频,他对此的修复对我不起作用。
图库.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