Separate routes if subdomain is present in rails
Is there a way to separate routes in rails 3.1 when a subdomain is present? I want to use one collecti开发者_C百科on of routes when subdomains is used and one if not.
e.g
if request.subdomain.present?
root ....
resources ...
else
root ....
resources ...
end
Is something like this possible?
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
精彩评论