所以我利用 Ryan Bates 嵌套模型表单 railscast 和回形针进行多文件上传设置。任何人我在“附件”属性上的批量分配有问题,想知道堆栈上的一些好心人是否可以指出我哪里出错了。
公寓.rb
has_many :attachments
accepts_nested_attributes_for :attachments
attr_accessible :title, :body, :bedrooms, :bathrooms, :rent, :security_deposit, :neighborhood, :intersection, :sqfeet, :attachments_attributes, :attachments
附件.rb
attr_accessible :caption, :apartment_id
belongs_to :apartment
has_attached_file :image
公寓 form.html.erb
<%= f.simple_fields_for :attachments do |builder| %>
<%= render 'attachments_fields', f: builder %>
<% end %>
附件字段.html.erb
<%= f.file_field :attachments %><br />
请求参数
{"utf8"=>"✓", "authenticity_token"=>"MruMcUX3k43JxHv9jJMLxxipf5By0cBsk2d+L6O0SL4=", "apartment"=>{"title"=>"", "bedrooms"=>"", "bathrooms"=>"", "rent"=>"", "security_deposit"=>"", "intersection"=>"", "body"=>"", "attachments_attributes"=>{"1378213436357"=>{"attachments"=>#<ActionDispatch::Http::UploadedFile:0x007fa089c546e0 @original_filename="Ixia.gif", @content_type="image/gif", @headers="Content-Disposition: form-data; name=\"apartment[attachments_attributes][1378213436357][attachments]\"; filename=\"Ixia.gif\"\r\nContent-Type: image/gif\r\n", @tempfile=#<Tempfile:/var/folders/7l/66jh7_ld5ng5cdhdslpxc0180000gn/T/RackMultipart20130903-15330-1jplpe6>>}}}, "neighborhood"=>"Albany Park", "commit"=>"Create Apartment", "action"=>"create", "controller"=>"apartments"}
非常感谢!