簡體   English   中英

通過Paperclip進行多次上傳時出現批量分配問題

[英]Multiple Uploads via Paperclip issue with Mass Assignment

因此,我使用了Ryan Bates嵌套模型表格railscast以及回形針來進行多文件上傳設置。 我在'attachments'屬性上對大規模分配有任何疑問,並且想知道堆棧中的某些友善人士是否可以指出我出了問題的地方。

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"}

非常感謝!

將您的attachment_fields.html.erb更新為:

<%= f.file_field :image %><br />

而不是<%= f.file_field :attachments %>

參考: 回形針自述文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM