Iteration D2: Connecting Products to Carts
We’re looking at sessions because we need somewhere to keep our shopping cart. We’ll cover sessions in more depth in Rails Sessions, but for now let’s move on to implement the cart.
Let’s keep things simple. A cart contains a set of products. Based on the Initial guess at application data diagram, combined with a brief chat with our customer, we can now generate the Rails models and populate the migrations to create the corresponding tables:
| depot> bin/rails generate scaffold LineItem product:references cart:belongs_to |
| ... |
| depot> bin/rails db:migrate |
| == CreateLineItems: migrating ============================================== |
| -- create_table(:line_items) ... |
Get Agile Web Development with Rails 7 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.