27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

This chapter covers<br />

� Building a nested resource<br />

� Declaring data associations between two<br />

database tables<br />

� Working with objects within an association<br />

99<br />

Nested resources<br />

With the project resource CRUD done, the next step is to set up the ability to create<br />

tickets within the scope of a given project. The term for performing actions for<br />

objects within the scope of another object is nesting. This chapter explores how to<br />

set up nested routing for Ticket resources by creating a CRUD interface for them,<br />

scoped underneath the projects resource that you just created.<br />

5.1 Creating tickets<br />

To add the functionality to create tickets underneath the projects, you first develop<br />

the Cucumber features and then implement the code required to make them pass.<br />

Nesting one resource under another involves additional routing, working with associations<br />

in Active Record, and using more before_filters. Let’s get into this.<br />

To create tickets for your application, you need an idea of what you’re going to<br />

implement. You want to create tickets only for particular projects, so you need a

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!