Hey all, I've been doing some work with nested resources today, and I spent some time banging my head against named routes for nested resources. Thought I'd share with the group a bit...
Consider the following: map.resources :people do |people| people.resources :posts end Intuitively, I tried using named routes like person_new_post_url(:person_id => @person). This didn't work, rather to my surprise. Turns out you have to manually set :name_prefix. Like so: map.resources :people do |people| people.resources :posts, :name_prefix => 'person_' end For those of you working with nested resources and named routes, is this the approach you use? Part of why I'm even bothering with this is because I also map the posts by themselves without being nested underneath the people resource. I was toying with showing shorter URLs for a logged-in user who is doing stuff -- a public vs. administrative sort of setup -- and I needed the named routes to match. What do you guys think: if a nested call to map.resources is already setting the :path_prefix according to the parent resource, shouldn't it figure out a name_prefix as well? Should I just memorize this case and move on, or do you think this is an example of violating the principle of least surprise that is worth discussing? -- Nick Zadrozny _______________________________________________ Sdruby mailing list [email protected] http://lists.sdruby.com/mailman/listinfo/sdruby
