One controller for collection/member actions and singleton actions

3 views
Skip to first unread message

Chris Hapgood

unread,
Dec 16, 2009, 12:31:44 PM12/16/09
to resources_controller
Curious if you have ever tried to use one controller to handle both
collections and singletons of the same class. Example:

map.resources :widgets
map.resources :users do |u|
u.resource :widget
end

Rails will normally route the resources (collection and member) and
the resource (singleton) to the WidgetsController. And I think it's
possible to write coherent actions for this scenario (at least in my
use case). But RC can't deal with the differing find semantics. Any
thoughts?

I would even be willing to sneak in an RC-specific flag to let RC know
which scenario is in play:

map.resources :widgets
map.resources :users do |u|
u.resource :widget, :rc_arity => 'singleton'
end

Although there is enough information in the route to infer the correct
scenario.

BTW, compatibility report & kudos: I'm on 2.3.4+++ right now, and RC
continues to carry a heavy load with few complaints! Great stuff.
Really great stuff.
Reply all
Reply to author
Forward
0 new messages