marc
August 20, 2007, 3:45pm
1
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!
marc
August 20, 2007, 5:48pm
2
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
On Aug 20, 9:47 am, “Jeremy McAnally” [email protected]
marc
August 20, 2007, 7:25pm
3
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.
–Jeremy
On 8/20/07, AndyV [email protected] wrote:
You may be having trouble generating routes like I did when I first
On 8/20/07, Marc [email protected] wrote:
owner.resources :dogs,
–http://www.jeremymcanally.com/
My free Ruby e-book:http://www.humblelittlerubybook.com/book/
My blogs:http://www.mrneighborly.com/http://www.rubyinpractice.com/
–
http://www.jeremymcanally.com/
My free Ruby e-book:
http://www.humblelittlerubybook.com/book/
My blogs:
http://www.rubyinpractice.com/
marc
August 20, 2007, 10:44pm
4
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
On Aug 20, 11:47 pm, “Jeremy McAnally” [email protected]
marc
August 20, 2007, 3:56pm
5
You may be having trouble generating routes like I did when I first
stated playing with it.
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:
…whenever you need it.
–Jeremy
On 8/20/07, Marc [email protected] wrote:
owner.resources :cats,
:controller => 'cats',
:singular => 'cat',
:name_prefix => 'owner_'
end
Just having a bit of trouble with routes… thanks!
–
http://www.jeremymcanally.com/
My free Ruby e-book:
http://www.humblelittlerubybook.com/book/
My blogs:
http://www.rubyinpractice.com/
marc
August 20, 2007, 10:54pm
6
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 =)