Capturing the Order Details
Explore how to implement order capturing and validation in a Rails e-commerce app. Learn to populate order models from forms, link cart items, validate input, handle saving with feedback, and manage session carts, enabling a functional checkout experience.
We'll cover the following...
Feel free to make other changes, but only the first is currently used in the functional tests. For these tests to pass, we’ll need to implement the model.
Let’s implement the create() action in line 1 in the orders_controller.rb. This method has to do the following:
-
Capture the values from the form to populate a new
Ordermodel object. -
Add the line items from our cart to that order.
-
Validate and save the order. If this fails, display the appropriate messages and let the user correct any problems.
-
Once the order is successfully saved, delete the cart, redisplay the catalog page, and display a message confirming that the order has been placed.
We define the relationships themselves, first from the line item ...