Same routes across multiple resources

I am working on a new rail application and came up with this scenario. I need the same routes across multiple resources, but I don't want to repeat the same lines.

Is there a DRY way to do 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 would be appreciated.

+3


source to share


1 answer


Try:



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

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

      

+5


source







All Articles