Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top