What's the rationale behind the controller names of nested resources?
e.g:
map.resources :projects do |project|
project.resources :images
end
map.resources :galleries do |gallery|
gallery.resources :images
end
This results in the urls for /projects/:id/images and /galleries/:id/images both going to the index action on the images controller. Even if I were using a common image model and polymorphic associations I'd thought it'd still be better to go to a project_images and gallery_images controller otherwise you need to disambiguate whether you need to load a project or gallery.
I know I can override the controller (extra typing) or change the routing definition to :project_images (ugly urls), etc. But it seems to me that the most common usage scenario would have the controller prefixed with the singular name of the parent.
I have a patch which changes the behavior to this, but if it's 'Not The Right Way' please can someone enlighten me
What's the rationale behind the controller names of nested resources?
e.g:
map.resources :projects do |project|
project.resources :images
end
map.resources :galleries do |gallery|
gallery.resources :images
end
This results in the urls for /projects/:id/images and /galleries/:id/
images both going to the index action on the images controller. Even
if I were using a common image model and polymorphic associations I'd
thought it'd still be better to go to a project_images and
gallery_images controller otherwise you need to disambiguate whether
you need to load a project or gallery.
That's by design. You can use the presence of gallery_id or project_id
in params to disambiguate where the request is coming from. I'm using
this all over Highrise.
I know I can override the controller (extra typing) or change the
routing definition to :project_images (ugly urls), etc. But it seems
to me that the most common usage scenario would have the controller
prefixed with the singular name of the parent.
That's not the usage pattern I've observed. I've wanted to use the
same controller for all the nested resources I've encountered. I don't
think having to specify the controller name is undue hardship in the
case that this is not desired.
I'm guessing that the namespace option should be applied to nested resources - edge currently only applies it to associations. I've created a ticket (9399) with a patch to fix this.
I'm guessing that the namespace option should be applied to nested
resources - edge currently only applies it to associations. I've
created a ticket (9399) with a patch to fix this.