控制购物车的最佳方法

发布于 2024-08-04 18:41:44 字数 137 浏览 2 评论 0原文

我正在尝试构建一个简单的购物车,我阅读了有关控制它们的内容,并发现有 3 种方法可以控制它们。 一种是cookie,另一种是基于会话的,最后一种是数据库模型。 我想知道哪一个是更好的选择? 有人说数据库方法更好,但也更难。 我也在寻找数据库模型教程......

I am trying to build a simple shopping cart, i read about controlling them and see there are 3 ways to control them.
one is cookies, another one is session based, and last one is database model.
I am wondering which one is better choice ?
some told that database method is better but its harder too.
I am also looking for database model tutorial...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

公布 2024-08-11 18:41:44

您真正谈论的似乎是会议。当用户结帐时,您可能会在会话中存储一些购物车数据,因此这可能是您感到困惑的原因。

您的问题的答案取决于您在会话中存储的数据类型和数量。 Cookie 有大小限制,您不应在其中存储未加密的敏感用户数据。有些人会说你甚至不应该将信用卡号码之类的东西加密在那里。数据库支持的会话的缺点是您必须经常清除它们。这可以通过 cron 作业运行的 rake 任务轻松完成,但这仍然是您必须考虑的事情。文件支持的会话并不经常使用,还有更多只是为了让您快速启动并运行某些东西。我不会在生产中运行文件支持的会话。

Authlogic 是一个可以引入到 Rails 项目中的宝石。它提供了一个您可以继承的 UserSession 模型。它有很多功能并且完全可配置。

What you really seem to be talking about is sessions. You will probably store some of your shopping cart data in the session while the user is checking out, so this is where your confusion might have come from.

The answer to your question depends on what kind and how much data you are storing in the session. Cookies have size limits and you should not be storing sensitive user data in them unencrypted. Some would say you shouldn't even put things like credit card numbers in there encrypted. The downside to DB-backed sessions you have to clear them out every so often. This is easily done with a rake task run via a cron job, but it's still something you have to think about. File-backed sessions aren't used often and are there more just to get you up and running with something quickly. I wouldn't run with file-backed sessions in production.

Authlogic is a gem that you can pull into your Rails project. It provides a UserSession model that you can inherit from. It's got a lot of features and is fully configurable.

猫九 2024-08-11 18:41:44

我构建的购物车将信息存储在数据库中,并将 cart_id 存储在会话中。那么你只需要一份每隔几天从数据库清理未完成的购物车的工作。

Shopping carts that I have built store the information in the database, and just store the cart_id in the session. Then you just need a job that cleans up unfulfilled shopping carts from db every few days.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文