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.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---