# Accessing object in params hash

**URL:** <https://www.ruby-forum.com/t/accessing-object-in-params-hash/132667>\
**Category:** Rails\
**Created:** [March 22, 2008, 10:02pm UTC](https://www.ruby-forum.com/t/accessing-object-in-params-hash/132667 "2008-03-22T22:02:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 22, 2008, 10:02pm UTC](https://www.ruby-forum.com/t/accessing-object-in-params-hash/132667/1 "2008-03-22T22:02:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 22, 2008, 10:15pm UTC](https://www.ruby-forum.com/t/accessing-object-in-params-hash/132667/2 "2008-03-22T22:15:25Z")

</div>

On Mar 22, 9:02 pm, Steve G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 22, 2008, 10:20pm UTC](https://www.ruby-forum.com/t/accessing-object-in-params-hash/132667/3 "2008-03-22T22:20:57Z")

</div>

Frederick C. wrote:

> On Mar 22, 9:02 pm, Steve G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> 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
