Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Same routes in multiple resources

I am working on a new rails application and came to this scenario. 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.

like image 768
Deepak Mahakale Avatar asked Mar 09 '23 14:03

Deepak Mahakale


1 Answers

Try:

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

resources :contacts, :concerns => [:associate]
resources :doctors, :concerns => [:associate]
like image 171
Willem Avatar answered Mar 15 '23 01:03

Willem