Week 11 Rails Comprehensive - Code-the-Dream-School/rails-guidebook GitHub Wiki

Week Topic Learning Objectives Key Resources
11 Rails Comprehensive
  • Practice all Rails skills learned to this point
  • Understand the dynamic population of dropdown lists in ERB files
  • Understand foreign keys and foreign key exceptions
  • Learn how to create factories for objects that have associations through foreign keys
Lesson Materials - See Coding Assignment

Coding Assignment

Lesson 10 Outline

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.

What Students Will Learn:

  • 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.

What Students Will Do:

  1. Create a New Model:

    • Generate an Order model with attributes: product_name, product_count, and customer_id.
    • Establish a belongs_to association with the Customer model.
  2. Set Up Routes:

    • Create routes for CRUD operations for Order, without nesting under Customer.
  3. Develop the Controller:

    • Implement index, show, new, edit, create, update, and destroy methods in OrdersController.
  4. Create Views:

    • Develop views for Order: edit, index, new, and show.
    • Implement a shared partial form for new and edit views.
    • Update the show view for Customer to list associated Orders.
  5. Add Validations:

    • Ensure presence of product_name, product_count, and customer in the Order model.
  6. Write Tests:

    • Create model tests for Order to validate the correctness of validations.
    • Write request tests for OrdersController to verify CRUD operations.
  7. Improve the Customer Index View:

    • Update the Customer index view to display a table with customer details and order counts.
  8. Handle Foreign Key Exceptions:

    • Implement error handling for foreign key constraints in the Customer destroy action.
  9. 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.

Checklist

  • Generate Order model with attributes: product_name, product_count, customer_id.
  • Establish belongs_to :customer association in the Order 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, and show.
  • Implement a shared partial form for new and edit views.
  • Update Customer show view to list associated Orders.
  • Add validations to Order model for presence of product_name, product_count, and customer.
  • 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.
⚠️ **GitHub.com Fallback** ⚠️