私は自分の開発の段階で、深く (>1) ネストされたリソースは努力する価値がないと考えています。
私はこのようなものを持っています:
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
キッカーは、コメントが他のリソースに対して多態的であることです。私の意図は、~/first-level/34/comments、~/first-level/34/second-level/56/third-level/comments などのようなきれいな URL にすることでした。
これまでの問題は、入れ子になったときのポリモーフィック ルートが問題を引き起こすだけです。例として、Ryan Bates Railscasts をいくつかフォローしています。たとえば、最初のレベルで polymorphic_path を使用しようとすると、正常に動作し、次のようになります。
polymorphic_path([@commentable, comments]) => ~/first-level/34/comments
しかし、同じコードは次のように~/first-level/34/second-level/23
失敗します:
undefined method 'second-level_comment_path' for #<#<Class:0x007fcc4acfbe58>:0x007fcc4ae73d08>
しかし、ルートを見ると、実際の名前付きルートはfirst-level_second-level_comment
. second-level_comment_path
基本的にエイリアスするために手動で作成しようとしましfirst-level_second-level_comment
たが、それを機能させることもできなかったようです。
誰かがここで明らかなエラーを指摘できない限り、私はこのアプローチ (http://weblog.jamisbuck.org/2007/2/5/nesting-resources) に傾いており、これらのネストを解除するだけです。階層を表示するためのブレッドクラム スタイルのナビゲーションがあるので、それで十分であり、見れば見るほど URL が扱いにくくなります。