On Oct 11, 7:54 am, Jay Pangmi <[EMAIL PROTECTED]>
wrote:
> Sorry, I'm back again as I couldn't go much far than I thought.. I did
> the following:
>
> def add_to_cart
> cart=Cart.create(......)
> session[:cart_id] = cart.id
> [EMAIL PROTECTED](session[:cart_id])
> end
>
> Now, session[:cart_id]=cart.id is only storing the id of the newly added
> cart item so, Cart.find(session[:cart_id]) is only giving me one row.
> Hence, despite the fact that a customer has added multiple items in the
> cart, I could only show the latest item added in the cart to the
> customer. So, thought of using this:
>
> @cart_ids = []
> session[:cart_id] = cart.id
> @cart_ids << session[:cart_id]
How could that ever work? That instance variable doesn't survive
across requests. You would need something like
cart=Cart.create(......)
session[:cart_ids] ||= []
session[:cart_ids] << cart.id
You can then later use Cart.find(session[:cart_ids]) to get all those
cart objects back.
Fred
>
>
> but couldn't think of the way to iterate through each id in the
> @cart_ids and show the result in the add_to_cart.rhtml. Any better
> suggestion or solution for this??? thanks..
> --
> Posted viahttp://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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---