繁体   English   中英

如何为Rails路由设置特定的子域?

[英]How to setup specific subdomain for rails routes?

我正在尝试为我的站点在Rails中设置一个子域。 我跟随着路轨来做到这一点。 http://railscasts.com/episodes/221-subdomains-in-rails-3?view=comments

我有一个问题。 我想声明一个特定的静态子域作为辅助主页。

  constraints(Subdomain) do
    match '/' => 'static_pages#secondary_home'
  end

  root to: 'static_pages#home'

LIB / subdomain.rb

class Subdomain
  def self.matches?(request)
    request.subdomain.present? && request.subdomain.eql? "secondaryhome"
  end
end

所以现在我希望只有secondaryhome.lvh.me:3000指向我的辅助主页。 (lvh.me是指向本地主机的外部域)。但是,我拥有的任何子域(例如abc.lvh.me:3000)似乎都指向辅助主目录,而我希望它默认为我的主根目录。 我该怎么办?

我们已经做到了这一点:

#config/routes.rb
constraints({ subdomain: "secondaryhome" }) do
    match '/' => 'static_pages#secondary_home'
end

这为lvh.me:3000 with constraint { subdomain: "secondaryhome" }设置了一个lvh.me:3000 with constraint { subdomain: "secondaryhome" }的路由-仅该路由有效

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM