Week 11 Rails Comprehensive - Code-the-Dream-School/rails-guidebook GitHub Wiki
| Week | Topic | Learning Objectives | Key Resources |
|---|---|---|---|
| 11 | Rails Comprehensive |
|
Lesson Materials - See Coding Assignment Coding Assignment |
Overview: In this lesson, students will apply their Ruby on Rails skills to extend a customer-order application by creating and managing a new Order model. The lesson focuses on building a complete CRUD interface for Order, including validations, associations, and tests.
-
Model Creation: Define a new
Ordermodel with attributes and associations. -
Routing and Controller: Set up routes and implement CRUD actions in the
OrdersController. -
Views: Create and manage views for the
Ordermodel. -
Validations and Error Handling: Add validations to the
Ordermodel and handle errors. - Testing: Write model and request tests to ensure proper functionality.
- Foreign Key Constraints: Manage foreign key constraints and handle associated exceptions.
-
Create a New Model:
- Generate an
Ordermodel with attributes:product_name,product_count, andcustomer_id. - Establish a
belongs_toassociation with theCustomermodel.
- Generate an
-
Set Up Routes:
- Create routes for CRUD operations for
Order, without nesting underCustomer.
- Create routes for CRUD operations for
-
Develop the Controller:
- Implement
index,show,new,edit,create,update, anddestroymethods inOrdersController.
- Implement
-
Create Views:
- Develop views for
Order:edit,index,new, andshow. - Implement a shared partial form for
newandeditviews. - Update the
showview forCustomerto list associatedOrders.
- Develop views for
-
Add Validations:
- Ensure presence of
product_name,product_count, andcustomerin theOrdermodel.
- Ensure presence of
-
Write Tests:
- Create model tests for
Orderto validate the correctness of validations. - Write request tests for
OrdersControllerto verify CRUD operations.
- Create model tests for
-
Improve the Customer Index View:
- Update the
Customerindex view to display a table with customer details and order counts.
- Update the
-
Handle Foreign Key Exceptions:
- Implement error handling for foreign key constraints in the
Customerdestroy action.
- Implement error handling for foreign key constraints in the
-
Submit Work:
- Commit and push changes to the
lesson10branch. - Create a pull request and include a link to the pull request with the homework submission.
- Commit and push changes to the
- Generate
Ordermodel with attributes:product_name,product_count,customer_id. - Establish
belongs_to :customerassociation in theOrdermodel. - Set up CRUD routes for
Orderresource. - Create
OrdersControllerwith methods:index,show,new,edit,create,update,destroy. - Develop views for
Order:edit,index,new, andshow. - Implement a shared partial form for
newandeditviews. - Update
Customershow view to list associatedOrders. - Add validations to
Ordermodel for presence ofproduct_name,product_count, andcustomer. - Write model tests for
Ordervalidations. - Write request tests for
OrdersControllerCRUD actions. - Enhance
Customerindex view with a table displaying customer details and order counts. - Handle foreign key exceptions in
Customerdestroy action. - Commit and push changes to
lesson10branch. - Create a pull request and include a link with the homework submission.