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
Order
model with attributes and associations. -
Routing and Controller: Set up routes and implement CRUD actions in the
OrdersController
. -
Views: Create and manage views for the
Order
model. -
Validations and Error Handling: Add validations to the
Order
model 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
Order
model with attributes:product_name
,product_count
, andcustomer_id
. - Establish a
belongs_to
association with theCustomer
model.
- 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
, anddestroy
methods inOrdersController
.
- Implement
-
Create Views:
- Develop views for
Order
:edit
,index
,new
, andshow
. - Implement a shared partial form for
new
andedit
views. - Update the
show
view forCustomer
to list associatedOrders
.
- Develop views for
-
Add Validations:
- Ensure presence of
product_name
,product_count
, andcustomer
in theOrder
model.
- Ensure presence of
-
Write Tests:
- Create model tests for
Order
to validate the correctness of validations. - Write request tests for
OrdersController
to verify CRUD operations.
- Create model tests for
-
Improve the Customer Index View:
- Update the
Customer
index 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
Customer
destroy action.
- Implement error handling for foreign key constraints in the
-
Submit Work:
- Commit and push changes to the
lesson10
branch. - Create a pull request and include a link to the pull request with the homework submission.
- Commit and push changes to the
- Generate
Order
model with attributes:product_name
,product_count
,customer_id
. - Establish
belongs_to :customer
association in theOrder
model. - Set up CRUD routes for
Order
resource. - Create
OrdersController
with methods:index
,show
,new
,edit
,create
,update
,destroy
. - Develop views for
Order
:edit
,index
,new
, andshow
. - Implement a shared partial form for
new
andedit
views. - Update
Customer
show view to list associatedOrders
. - Add validations to
Order
model for presence ofproduct_name
,product_count
, andcustomer
. - Write model tests for
Order
validations. - Write request tests for
OrdersController
CRUD actions. - Enhance
Customer
index view with a table displaying customer details and order counts. - Handle foreign key exceptions in
Customer
destroy action. - Commit and push changes to
lesson10
branch. - Create a pull request and include a link with the homework submission.