6

I have a model Model that can be access from many ways: by subdomain or a 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

So I currently have to duplicate all the routes for the two cases.

Is there any way to declare it only once?

efji
  • 63
  • 2

1 Answers1

4
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

Community
  • 1
  • 1
fl00r
  • 79,728
  • 29
  • 207
  • 231