Persisting a shopping cart in Ruby on Rails

╄→尐↘猪︶ㄣ 提交于 2019-12-04 21:19:58

问题


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.
  3. Have a cart table, and store the cart id in a cookie session.

Have i missed any? which is the best to roll with please?

Thanks


回答1:


#3 is probably your best bet, because that gives you the most freedom/flexibility. 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. You're setting yourself up for nasty bugs where large shopping carts get corrupted, particularly in older browsers.




回答2:


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).

  • http://railscasts.com/episodes/141-paypal-basics
  • http://railscasts.com/episodes/142-paypal-notifications
  • http://railscasts.com/episodes/143-paypal-security
  • http://railscasts.com/episodes/144-active-merchant-basics
  • http://railscasts.com/episodes/145-integrating-active-merchant
  • http://railscasts.com/episodes/146-paypal-express-checkout


来源:https://stackoverflow.com/questions/3431234/persisting-a-shopping-cart-in-ruby-on-rails

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