Chapter 5. Nested resources

 

This chapter covers

  • Nested routing helpers and named routes
  • Creating associations to link models together
  • Making tests more expressive using let and let!

The project resource CRUD was completed in chapter 4, so the next step is to set up the ability to create tickets within the scope of a given project. This chapter explores how to set up a nested resource in Rails, by defining routes for Ticket resources and creating a CRUD interface for them, all scoped under the project resource that you just created.

In this chapter, you’ll see how easy it is to retrieve all ticket records for a specific project and perform CRUD operations on them, mainly with the powerful associations interface that Rails provides through its Active Record component.

5.1. Creating tickets

To add the functionality to create tickets under projects, you’ll first develop the Capybara features, and then implement the code required to make them pass. Nesting one resource under another involves additional routing, working with associations in Active Record, and using more calls to before_action. Let’s get into this.

5.2. Viewing tickets

5.3. Editing tickets

5.4. Deleting tickets

5.5. Summary