I am at the point in my development that I am thinking that deeply (>1) nested resources are not worth the effort.
I have something like this:
resources :first-level do
resources :comments
resources :second-level do
resources :comments
resources :first-child do
resources :comments
end
resources :second-child do
resources :comments
end
resources :third-child do
resources :comments
end
end
end
The kicker is that the comments are polymorphic to the other resources. My intent was to have clean looking URLs like ~/first-level/34/comments, ~/first-level/34/second-level/56/third-level/comments etc.
The problem so far is the polymorphic routes when nested cause nothing but grief. I am following a couple of Ryan Bates Railscasts as an example. For example if I try to use polymorphic_path on the first level it works fine and I get:
polymorphic_path([@commentable, comments]) => ~/first-level/34/comments
but the same code on ~/first-level/34/second-level/23
fails with:
undefined method 'second-level_comment_path' for #<#<Class:0x007fcc4acfbe58>:0x007fcc4ae73d08>
but when I look at my routes the actual named route is first-level_second-level_comment
. I tried to manually create that second-level_comment_path
to basically alias to first-level_second-level_comment
but I could not seem to make that work either.
Unless someone can point out an obvious error here I am leaning towards this approach (http://weblog.jamisbuck.org/2007/2/5/nesting-resources) and just un-nesting these. I have a breadcrumb style navigation to show the hiearchy so that should suffice and the more I look at it the urls do get a bit unwieldily.