Why do I get 1 as id for all locations?


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] ||= []

To populate carts table:

def add_to_cart
cart=Cart.create(:location => …)
@cart << cart.id

To save in the table:

def save_details
for item in @cart_items
@camp_id=Campsite.find(:all, :select=>‘id’,
:conditions=>[“camp_location = ?”,item.location])
Booking.create(:location_id=>@camp_id, …)

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.


Never mind, I fixed it.