我有一个可以通过多种方式访问的模型模型:通过子域或令牌
我有以下路线
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
所以我目前必须复制这两种情况的所有路线。
有没有办法只声明一次?
答案 0 :(得分: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