Iteration E1: Creating a Smarter Cart
Associating a count with each product in our cart is going to require us to modify the line_items table. We’ve used migrations before; for example, we used a migration in Applying the Migration to update the schema of the database. While that was as part of creating the initial scaffolding for a model, the basic approach is the same:
| | depot> bin/rails generate migration add_quantity_to_line_items quantity:integer |
Rails can tell from the name of the migration that you’re adding columns to the line_items table and can pick up the names and data types for each column from the last argument. The two patterns that Rails matches on are add_XXX_to_TABLE and remove_XXX_from_TABLE, where ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access