简体   繁体   English

在Ruby on Rails中坚持购物车

[英]Persisting a shopping cart in Ruby on Rails

Currently developing a shopping cart, the options for persisting the cart, as i see them are: 目前正在开发一个购物车,坚持购物车的选项,如我所见:

  1. Store the entire cart object in a sessions table. 将整个购物车对象存储在会话表中。
  2. Store the entire cart object in a cookie session. 将整个购物车对象存储在cookie会话中。
  3. Have a cart table, and store the cart id in a cookie session. 有一个购物车表,并将购物车ID存储在cookie会话中。

Have i missed any? 我错过了吗? which is the best to roll with please? 请哪个最好滚?

Thanks 谢谢

#3 is probably your best bet, because that gives you the most freedom/flexibility. #3可能是你最好的选择,因为这给你最大的自由/灵活性。 Say someday you want users to be able to save their shopping carts between sessions. 总之,有一天你希望用户能够在会话之间保存他们的购物车。 Or you want to keep shopping cart histories for your users. 或者您希望为用户保留购物车历史记录。 Or you decide to run some analytics on shopping cart data. 或者您决定对购物车数据进行一些分析。

#2 is a bad solution because of the cookie size limits on browsers. 由于浏览器的cookie大小限制,#2是一个糟糕的解决方案。 You're setting yourself up for nasty bugs where large shopping carts get corrupted, particularly in older browsers. 您正在为大型购物车损坏的恶劣错误做好准备,尤其是在旧版浏览器中。

Check out the Railscasts episodes #141-#146... Helped me a lot with shopping cart/checkout related stuff (though the episodes don't directly address your question, you will get to see a straightforward method of implementing a shopping cart). 查看Railscasts剧集#141-#146 ...通过购物车/结账相关的东西帮助了我很多(尽管剧集没有直接解决你的问题,你会看到一个实施购物车的简单方法) 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM