Accessing object in params hash

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

On Mar 22, 9:02 pm, Steve G. [email protected]
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?

Fred

Frederick C. wrote:

On Mar 22, 9:02 pm, Steve G. [email protected]
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?

Fred

Actually Fred that is exactly what I wanted. To many hours at the
computer had me going whacky. Thanks again for your help.

steve

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs