On Oct 10, 2:56 pm, Jay Pangmi <[EMAIL PROTECTED]>
wrote:
> Frederick Cheung wrote:
> > This doesn't seem to make any sense. For example the @cart_items array
> > will only ever contain 1 item, you are storing the whole cart object
> > in the session (what's the point of storing it in the database and the
> > session ?)
>
> session[:cart]=Cart.new(cartobj), what is this doing actually I'm not
> sure?
Your code actually says
session[:cart] ||= Cart.new(cartobj)
what this does is:
- if session[:cart] is set, do nothing
- if not create a new instance of cart and store it in the session.
> As you said just to store carts id in the session, how can I do
> that? and while emptying the cart how can I get all the carts' id stored
> in the session and delete the records with that id from the carts table?
> With my current way, how can I validate individual details coz currently
> its all coming as params[:cart] coz first I have to validate and if
> alright save in the database.
>
You would do something like like
cart = Cart.create(...)
session[:cart_id] = cart.id
When you need to access the cart later you would do
cart = Cart.find session[:cart_id]
and then do stuff with the instance of cart (eg destroy it)
> > Actually if you check your code you'll find that beyond the first time
> > you call add_to_cart it won't actually do anything.
>
> can you please show me how? I'm not yet familiar with rails code.
>
> > Is you cart object actually an item in a cart (rather than the
> > container, as the name usually implies) ?
>
> My cart object (params[:cart]) is all the values passed from the browser
> by the customer like date, time etc and this values I'm saving to the
> database table. Hope this is what you trying to know.
That's not what I was asking. Some of what you were saying was
implying that a customer would have multiple carts at the same time,
whereas normally a person only ever has one cart (possibly containing
more than one thing). In that case you may not want to be persisting
the cart but the items in the cart (which might be what you're trying
to do already, but calling them carts just makes everything rather
confused).
Fred
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---