Rails 3 Resource: Share Custom Actions with Nested Resources
I have 2 resources events
and patients
resources :events do
collection do
get :upcoming
get :missed
end
end
resources :patients do
resources :events # does not have upcoming or mis开发者_如何学Gosed
end
Is there a way to have the events
nested resource within the patients
definition share the custom collection members from the primary events resource without having to define them again?
You can define a method in your routes file and can call it each time, as such keep DRY.
def events_actions
collection do
get :upcoming
get :missed
end
end
resources :events do
events_actions
end
resources :patients do
resources :events do
events_actions
end
end
Or take things even further:
def resources_events
resources :events do
collection do
get :upcoming
get :missed
end
end
end
resources_events
resources :patients do
resources_events
end
精彩评论