What happens to cart object when session expires?
I am following the Agile Web Development tutorials and I came across an annoying issue with the curr开发者_如何学JAVAent implementation. if the session changes or expires, the cart still exists in the database. How is Rails supposed to deal with these useless cart objects?
Thanks
Normally, a background process will delete old shopping carts every so often. You need to guard against recreating the session while someone is shopping. Doing so would be considered a bug if you are using it to track the shopping cart.
If you also have a user-id, then the shopping cart with a user-id may be retrievable into an other session. In that case, the background process may keep them around longer than an anonymous shopping cart. Retrieving lost carts takes a little more code, but may be a nice feature.
As you can see, every time that someone enter in your app, it creates a new Cart object (also obviously an new carts row) .... so in the end you will have a lot of useless cart row (for example for that users that don't checkout anything). One alternative is to change the way of the cart creation, and the other is like Billthor says: make a background process ( or rake task) to destroy all useless carts
精彩评论