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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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] ||= []
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.
Jay P. (Guest)
on 2008-10-16 04:23
Never mind, I fixed it.
This topic is locked and can not be replied to.