n-levels of nested resources in REST?


I find it would be very convenient to nest resources in two levels, so
a member is only sensible as a part of a club, and a fee pament is
only sensible in the context of a club and a member.
Is it possible to nest nested resources? How would the syntax be?

I have tried just nesting the assignment in routes.rb, but failed to
get it right

What do ou think? Is it possible?


map.resources :foos do |foo|
  foo.resources :bars do |bar|
    bar.resources :bazs


map.resources :foos do |foo|
  foo.resources :bars, :has_many => :bazs

Hi Fredrik,

Just a small warning from my own experience: nesting deeper than 1
level is not advised.
It will become very tedious to keep supplying the unneeded lower
levels of nesting in the url. If you know the "bar", you implicitly
also know the "foo". So there is really no need to keep suppling the
"foo", "bar" & "baz" all the time.

I generally use the following nesting setup:

map.resources :foos do |foo|
  foo.resources :bars

map.resources :bars do |bar|
  bar.resources :bazs

map.resources :bazs

This way your routes to the "baz" don't require a "foo".
Also, if you know the "baz" resource, you can always create a direct
route. For the index, new & create actions on "baz", you can the
choose the route which also requires the "bar" to define the scope.

Regards, Bas

+1. It's been widely discussed elsewhere and many of the insiders
suggest not nesting more than 2 levels deep.