开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜