So I made use of Ryan Bates nested model form railscast along with paperclip for a multiple file upload setup. Anywho Im having issues with mass assignment on the 'attachments' attribute and was wondering if some of the kind folks on stack could point out where I've gone wrong.
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
Apartments 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 />
Request Params
{"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"}
Many thanks!
Update your attachment_fields.html.erb
to:
<%= f.file_field :image %><br />
instead of <%= f.file_field :attachments %>
.
Reference: Paperclip readme