当子域存在时,有没有办法将rails 3.1中的路由分开?我想在使用子域时使用一个路由集合,如果不使用则使用一个。
例如
if request.subdomain.present?
root ....
resources ...
else
root ....
resources ...
end
这样的事情可能吗?
答案 0 :(得分:3)
class SubdomainRoute
def self.matches?(request)
request.subdomain.present? && request.subdomain != "www"
end
end
class NoSubdomainRoute
def self.matches?(request)
!request.subdomain.present?
end
end
constraints(NoSubdomainRoute) do
resources :profile # matches if there is not a subdomain
end
constraints(SubdomainRoute) do
resources :profile # matches if there is a subdomain
end