What happens to cart object when session expires?

狂风中的少年 提交于 2019-12-11 07:28:49

问题


I am following the Agile Web Development tutorials and I came across an annoying issue with the current 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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/5261542/what-happens-to-cart-object-when-session-expires

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!