Finding a Cart
Learn to create tables in SQLite for managing a cart.
We'll cover the following
As users browse our online catalog, they will (hopefully) select products to buy. The convention is that each selected item will be added to a virtual shopping cart held in our store. At some point, our buyers will have everything they need and will proceed to our site’s checkout, where they’ll pay for the items in their carts.
This means that our application will need to keep track of all the items added to the cart by the buyer. To do that, we’ll keep a cart in the database and store its unique identifier, cart.id
, in the session. Every time a request comes in, we can recover that identifier from the session and use it to find the cart in the database.
Let’s go ahead and create a cart:
depot> bin/rails generate scaffold Cart
depot> bin/rails db:migrate
Get hands-on with 1400+ tech skills courses.