# Multiple Nested Resources and Routes

**URL:** <https://discuss.rubyonrails.org/t/multiple-nested-resources-and-routes/46076>\
**Category:** rubyonrails-talk\
**Created:** [September 15, 2009, 7:45am UTC](https://discuss.rubyonrails.org/t/multiple-nested-resources-and-routes/46076 "2009-09-15T07:45:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jayoshi](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jayoshi](https://discuss.rubyonrails.org/u/Jayoshi)\
**Post date:** [September 15, 2009, 7:45am UTC](https://discuss.rubyonrails.org/t/multiple-nested-resources-and-routes/46076/1 "2009-09-15T07:45:20Z")

</div>

Hi

A noob question on using routes with multiple nested resources -

The nested resources are as follows -

-\> Projects &nbsp;&nbsp;-\> Assessments &nbsp;&nbsp;&nbsp;&nbsp;-\>Findings

A Project has many Assessments, an Assessment has many Findings.

At presents it all works well for the following URL -

/projects/1/assessments/1/

Now that I have added the code to nest Findings in the associated Assessment I need to add the correct Route. At the moment (understandably) I get "Route Error' when I browse to the following -

/projects/1/assessments/1/findings/1/

My routes.rb is currently configured as follows -

map.resources :projects, :has\_many =\> :assessments map.resources :assessments, :has\_many =\> :findings

What is the best route syntax for making this route work?

I also plan to add resolutions as nested resource to findings.

Thanks,

Jason

---

<div class="post-metadata">

**Author:** ![AppleII717](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/appleii717/32/3905_2.png) [@AppleII717](https://discuss.rubyonrails.org/u/AppleII717)\
**Post date:** [September 15, 2009, 10:32am UTC](https://discuss.rubyonrails.org/t/multiple-nested-resources-and-routes/46076/2 "2009-09-15T10:32:41Z")

</div>

> in routes.rb map.resources :projects do |project| project.resources :assessments do |assessment| assessment.resources :findings end end --

I'd consider adding :shallow =\> true. There is a lot of stuff out there about deeply nested routes (you don't need them!). Three deep is not necessarily deep, but you only need two in any case (parent/child) and only one in a lot of cases (edit/show)

You really only need: &nbsp;&nbsp;/assessments/1/findings/1/ Since assessment(1) knows who its parent is (project(1)).

It is strange that I found a post that seems to be trying to solve a similar real world problem with RoR and believe me it is a real learning experience. While I've be playing with rails for years I've only tried to develop a complex application recently. Consider:

&nbsp;&nbsp;map.resources :companies, :shallow =\> true do |company| &nbsp;&nbsp;&nbsp;&nbsp;company.resources :projects do |project| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;project.resources :jobs do |job| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;job.resources :stages do |stage| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stage.resources :stage\_assessments &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stage.resources :assessments, :through =\> :stage\_assessments, :only =\> [:index] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stage.resources :citizens, :through =\> :citizen\_stages &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stage.resources :citizen\_stages &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end

and

&nbsp;&nbsp;map.resources :assessments, :member =\> {:post =\> :post, :display =\> :get, :clone =\> :get, :application =\> :get },:shallow =\> true do | q\> &nbsp;&nbsp;&nbsp;&nbsp;q.resources :questions, :member =\> {:duplicate =\> :get}, :shallow =\> true do |a| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a.resources :answers &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end

And this is just a draft version - there is even more! This is really a dual application (maybe should be two). One side is project management where the customers projects consist of finding people (citizens) for jobs. The citizens go through a number of stages/phases (application, interview, training, etc). Each stage can have multiple assessments. In other words it job applicant screening process and those with the best scores in a phase move on to the next phase. I should point out that the stages and assessments can be customized for each job. The assessments mapping allows you to build or clone assessments that can be customized.

I think my major problem was trying to build this application was experimenting! That is generating the CRUD resources and then trying to define the resource route mapping. I should have started with the routes and defined "how" I was going to do things (the flow).

Steve
