我有2个资源events
和patients
resources :events do
collection do
get :upcoming
get :missed
end
end
resources :patients do
resources :events # does not have upcoming or missed
end
是否有办法让events
定义中的patients
嵌套资源与主要事件资源共享自定义集合成员,而无需再次定义它们?
答案 0 :(得分:1)
您可以在路线文件中定义一个方法,并且每次都可以调用它,因此请保持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
或者更进一步:
def resources_events
resources :events do
collection do
get :upcoming
get :missed
end
end
end
resources_events
resources :patients do
resources_events
end