Hi there, I am going batty with this problem and was hoping someone could help me out. I have a restaurant object that can have many boundaries (these are kept in a separate table and consist of a lat and long attribute). I have figured out how to pass multiple boundaries in the params hash upon a new restaurant creation. The params hash looks as follows: Parameters: {"restaurant"=>{"sun_open(4i)"=>"13", ..., "commit"=>"Submit Restaurant", "authenticity_token"=>"c319f495e108e4ef33881628b63f443c94bda27a", "action"=>"validate_and_save", "controller"=>"restaurants", "boundaries"=>[{"lng"=>"-79.37759399414062", "lat"=>"43.67581809328341"}, {"lng"=>"-79.39141273498535", "lat"=>"43.677711435998695"}], "image"=>[""]} Now in my controller I need to create a boundary object for each lat/lng in the hash. I would like to do something like this: params[:boundaries].each do |boundary| @restaurant.boundaries << Boundary.new(:lng => ''lng'', :lat => ''lat'' ) end unless params[:boundaries].nil However, I just can''t seem to be able to accomplish the task. I have played around with it and either it never goes into the loop or I get an error. Does anyone know what I need to do in the controller to correctly retrieve and create the boundaries? Thanks, steve -- 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 -~----------~----~----~----~------~----~------~--~---
On Mar 22, 9:02 pm, Steve Glaz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi there, > > I am going batty with this problem and was hoping someone could help me > out. I have a restaurant object that can have many boundaries (these are > kept in a separate table and consist of a lat and long attribute). > > I have figured out how to pass multiple boundaries in the params hash > upon a new restaurant creation. The params hash looks as follows: > > Parameters: {"restaurant"=>{"sun_open(4i)"=>"13", ..., "commit"=>"Submit > Restaurant", > "authenticity_token"=>"c319f495e108e4ef33881628b63f443c94bda27a", > "action"=>"validate_and_save", "controller"=>"restaurants", > "boundaries"=>[{"lng"=>"-79.37759399414062", > "lat"=>"43.67581809328341"}, {"lng"=>"-79.39141273498535", > "lat"=>"43.677711435998695"}], "image"=>[""]} > > Now in my controller I need to create a boundary object for each lat/lng > in the hash. I would like to do something like this: > > params[:boundaries].each do |boundary| > @restaurant.boundaries << Boundary.new(:lng => ''lng'', :lat => ''lat'' ) > end unless params[:boundaries].nil >Either I''ve misundersood or you just want params[:boundaries].each do |boundary| @restaurant.boundaries << Boundary.new(boundary) end unless params[:boundaries].nil? Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Mar 22, 9:02 pm, Steve Glaz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> Restaurant", >> @restaurant.boundaries << Boundary.new(:lng => ''lng'', :lat => ''lat'' ) >> end unless params[:boundaries].nil >> > Either I''ve misundersood or you just want > params[:boundaries].each do |boundary| > @restaurant.boundaries << Boundary.new(boundary) > end unless params[:boundaries].nil? > > FredActually Fred that is exactly what I wanted. To many hours at the computer had me going whacky. Thanks again for your help. steve -- 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 -~----------~----~----~----~------~----~------~--~---