多个资源中的相同路由

时间:2017-07-15 17:07:16

标签: ruby-on-rails routing dry

我正在开发一个新的rails应用程序并且遇到了这种情况。我希望在多种资源中使用相同的路线,但我不想重复相同的路线。

有没有办法干掉这个

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

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:7)

尝试:

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

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