Multiple Nested Resources and Routes

Hi

A noob question on using routes with multiple nested resources -

The nested resources are as follows -

-> Projects
-> Assessments
->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

Hi
Do like

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

Now the helper for /projects/1/assessments/1/findings/1/

is project_assessment_finding_url(projectid,assesmentid,findingid) it
will map to show action of findings controller

Sijo

On Sep 15, 3:44 am, Sijo Kg [email protected] wrote:

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:
/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:

map.resources :companies, :shallow => true do |company|
company.resources :projects do |project|
project.resources :jobs do |job|
job.resources :stages do |stage|
stage.resources :stage_assessments
stage.resources :assessments, :through
=> :stage_assessments, :only => [:index]
stage.resources :citizens, :through => :citizen_stages
stage.resources :citizen_stages
end
end
end
end

and

map.resources :assessments, :member => {:post => :post, :display
=> :get, :clone => :get, :application => :get },:shallow => true do |
q|
q.resources :questions, :member => {:duplicate => :get}, :shallow
=> true do |a|
a.resources :answers
end
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