所以我利用Ryan Bates嵌套模型表格railscast和paperclip进行多文件上传设置。我在“附件”属性上遇到批量分配的问题,并且想知道堆栈上的某些人是否可以指出我出错的地方。
Apartments.rb
has_many :attachments
accepts_nested_attributes_for :attachments
attr_accessible :title, :body, :bedrooms, :bathrooms, :rent, :security_deposit, :neighborhood, :intersection, :sqfeet, :attachments_attributes, :attachments
Attachment.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 %>
Atachment_fields.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"}
非常感谢!
答案 0 :(得分:0)
将您的attachment_fields.html.erb
更新为:
<%= f.file_field :image %><br />
而不是<%= f.file_field :attachments %>
。