Why do I get 1 as id for all locations?


#1

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.


#2

Never mind, I fixed it.