Forum: Ruby on Rails why do I get 1 as id for all locations??

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jay P. (Guest)
on 2008-10-15 15:37
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 <<

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.
Jay P. (Guest)
on 2008-10-16 04:23
Never mind, I fixed it.
This topic is locked and can not be replied to.