开发者

Separate routes if subdomain is present in rails

开发者 https://www.devze.com 2023-04-05 08:38 出处:网络
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.

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

精彩评论

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