Iterating over a params hash


#1

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


#2

params[:picture].each_pair {|key,value|

}

value will be the has containing values for each individual picture


#3

Thanks!


#4

Couldn’t you just do:
params[:picture].each_value |image|