Forum: Ruby on Rails Iterating over a params hash

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8e7e5b934fcbcdfb475072685755457f?d=identicon&s=25 Taylor Strait (Guest)
on 2007-03-18 23:57
I need to iterate over a params hash to upload multiple pictures at
once.  My example only has one file for clarity.  Any help would be
appreciated.


Hash from form:
{"commit"=>"Add", "picture"=>{"1"=>{"title"=>"dsfsdf",
"image_data_temp"=>"",
"image_data"=>#<File:C:/DOCUME~1/TAYLOR~1/LOCALS~1/Temp/CGI.1536.3>}}}


Controller:
      params[:picture].each { |image|
                            new_image = Image.new
                            new_image.title = image[:title]
                            new_image.image = image[:image_data]

                           if new_image.save
                           end }


Error:
TypeError in ImagesController#new
Symbol as array index
531eb73f8fbf05a197721d02b4e6aadb?d=identicon&s=25 Bogdan Ionescu (Guest)
on 2007-03-19 00:14
(Received via mailing list)
params[:picture].each_pair {|key,value|
...
}

value will be the has containing values for each individual picture
8e7e5b934fcbcdfb475072685755457f?d=identicon&s=25 Taylor Strait (Guest)
on 2007-03-19 01:44
Thanks!
1df9fc8ddf084661265bbae74a8d0b43?d=identicon&s=25 jko170 (Guest)
on 2007-05-05 10:54
(Received via mailing list)
Couldn't you just do:
params[:picture].each_value |image|
This topic is locked and can not be replied to.