Making Button Functional

Let’s continue to work on the button for adding products to the cart.

Before we push the button, we need to modify the create() method in the line items controller to expect a product ID as a form parameter. Here’s where we start to see how important the id field is in our models. Rails identifies model objects, and their corresponding database rows, by their id fields. If we pass an ID to create(), we’re uniquely identifying the product to add.

Get hands-on with 1200+ tech skills courses.