I’m working with a similar model in Episode 73, (my scenario is
editing multiple pictures for a product using attachment_fu).
And I’m getting an error when I try the technique suggested:
./views/admin/_form.rhtml
<% for picture in product.pictures %>
<% fields_for “product[picture_attributes][]”, picture do |
picture_form| %>
Title: <%= picture_form.text_field :title %>
<% end %>
./models/product.rb
def picture_attributes=(picture_attributes)
picture_attributes.each do |attributes|
pictures.build(attributes)
end
end
undefined method `stringify_keys!’ for “33”:String
Parameters: {“commit”=>“Edit”, “product”=>{“image_url”=>“shep.jpg”,
“price”=>“400.00”, “title”=>“German Shepard Lab Mix #2b”,
“category_ids”=>[“6”],
“picture_attributes”=>{“33”=>{“title”=>“asdf2”},
“24”=>{“title”=>“asdf”}, “27”=>{“title”=>“asdf”},
“30”=>{“title”=>“asdf”}}, “description”=>“3 year old german shepard
lab mix. Test!”}, “id”=>“23”, “picture”=>{“uploaded_data”=>""}}
I noticed in the video, it shows the “picture_attributes” parameter as
an array (not a hash is it shows on mine).