简体   繁体   English

多个资源中的相同路由

[英]Same routes in multiple resources

I am working on a new rails application and came to this scenario. 我正在开发一个新的rails应用程序并且来到这个场景。 I want same routes in multiple resources but I don't want to repeat the same lines. 我想在多个资源中使用相同的路由,但我不想重复相同的行。

Is there any way to DRY up this 有没有办法干这个

resources :contacts do
  collection do
    post :associate
    delete :remove
  end
end
resources :doctors do
  collection do
    post :associate
    delete :remove
  end
end

Any help will be appreciated. 任何帮助将不胜感激。

Try: 尝试:

concern :associate do
  collection do
    post :associate
    delete :remove
  end
end

resources :contacts, :concerns => [:associate]
resources :doctors, :concerns => [:associate]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM