How can I combine route declarations (subdomain or token)?

I have a model Model, which can be accessed from different ways: subdomain or token

I have the following routes

resources :model, :constraints => {:model_id => /[a-zA-Z0-9]{4}/} do ... (nested resources...) end resources :model, :constraints => {:subdomain => /.+/} do ... (same as above: nested resources...) end 

Therefore, I have to duplicate all the routes for two cases.

Is it possible to declare it only once?

+6
source share
1 answer
 def nested_routes get :some_route post :some route resources :some_resources end resources :model, :constraints => {:model_id => /[a-zA-Z0-9]{4}/} do nested_routes end resources :model, :constraints => {:subdomain => /.+/} do nested_routes end 

Related topic: Rails 3 Routes: DRY members

+4
source

Source: https://habr.com/ru/post/886623/


All Articles