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_'
  end

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 http://yourapp.com/owners/1/dogs/2 or what have you.

I suggest read the PDF mentioned here:

http://www.rubyinside.com/restful-rails-development-pdf-released-392.html

...and referring to this cheatsheet:

http://topfunky.com/clients/peepcode/REST-cheatsheet.pdf

...whenever you need it.

--Jeremy

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.

AndyV

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:

site_section_unit_text_activity_file_path(params[:site_id],
params[:section_id], params[:unit_id], params[:text_id],
params[:activity_id], params[:id])

Ridiculous. :slight_smile:

--Jeremy

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:

owner/1/dog/1
and
owner/1/cat/1

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

cat_path

should have been

owner_cat_path. doh.

Thanks all =)