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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
params[:picture].each_pair {|key,value| ... } value will be the has containing values for each individual picture On 3/19/07, Taylor Strait <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > 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 > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Couldn''t you just do: params[:picture].each_value |image| --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---