# Why do I get 1 as id for all locations?

**URL:** <https://www.ruby-forum.com/t/why-do-i-get-1-as-id-for-all-locations/150973>\
**Category:** Rails\
**Created:** [October 15, 2008, 1:37pm UTC](https://www.ruby-forum.com/t/why-do-i-get-1-as-id-for-all-locations/150973 "2008-10-15T13:37:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 15, 2008, 1:37pm UTC](https://www.ruby-forum.com/t/why-do-i-get-1-as-id-for-all-locations/150973/1 "2008-10-15T13:37:59Z")

</div>

## Hi, I’m trying to save all the details stored in the session in a table. This session holds ids of records in the carts table but as it holds just the name of location, I’m using for loop to try and find the id of each location. Here’s my implementation:

def find\_cart  
session[:cart\_ids] ||= []  
end

To populate carts table:

def add\_to\_cart  
@cart=find\_cart  
cart=Cart.create(:location =\> …)  
@cart \<\< cart.id  
end

To save in the table:

## def save\_details @cart\_items=Cart.find(session[:cart\_ids]) for item in @cart\_items @camp\_id=Campsite.find(:all, :select=\>‘id’, :conditions=\>[“camp\_location = ?”,item.location]) Booking.create(:location\_id=\>@camp\_id, …) end end

But, surprisingly, I only get 1 saved under location\_id under bookings  
table no matter which location I select and of course each location has  
different id in campsites table. Thanks.

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 16, 2008, 2:23am UTC](https://www.ruby-forum.com/t/why-do-i-get-1-as-id-for-all-locations/150973/2 "2008-10-16T02:23:14Z")

</div>

Never mind, I fixed it.
