multi nested resources

Hi guys,just wondering if someone could enlighten me about this.

Is it possible to have multi nested resources like

  map.resources :owners do |owner|
    owner.resources :dogs,
                   :controller => 'dogs',
                   :singular => 'dog',
                   :name_prefix => 'owner_'
    owner.resources :cats,
                   :controller => 'cats',
                   :singular => 'cat',
                   :name_prefix => 'owner_'

Just having a bit of trouble with routes... thanks!

You may be having trouble generating routes like I did when I first
stated playing with it. :slight_smile:

To generate a route to, say, a dog, you'll to provide something like this:

owner_dog_path(@owner_id, @dog_id)

Then Rails builds the URL off of the two id's to produce something
like or what have you.

I suggest read the PDF mentioned here:

...and referring to this cheatsheet:

...whenever you need it.


Jeremy is right -- you can next as deeply as you like. However, the
deeper you go the more difficult it becomes to create the routes.
I've got one spot in a project that is nested two levels deep and the
code gets a bit annoying.


I had nested about five levels deep on a project before we realized it
was stupid and we de-nested. The route generation looked something
like this:

params[:section_id], params[:unit_id], params[:text_id],
params[:activity_id], params[:id])

Ridiculous. :slight_smile:


Hmm but I'm not trying to nest too deeply. It's more like having two
equal nests? An Owner can have a dog as well as a cat (let's not get
into like polymorphism for this case first =). How do you denote that
on the routes?

url path would be like:


argh ignore what I have posted, I found out the error of my ways... I
forgot to put the prefix when i specified like:


should have been

owner_cat_path. doh.

Thanks all =)