[英]How to setup specific subdomain for rails routes?
I am trying to setup a subdomain for my site in rails. 我正在尝试为我的站点在Rails中设置一个子域。 I followed to rails cast to do this.
我跟随着路轨来做到这一点。 http://railscasts.com/episodes/221-subdomains-in-rails-3?view=comments
http://railscasts.com/episodes/221-subdomains-in-rails-3?view=comments
I am having an issue. 我有一个问题。 I want to state that for a specific static subdomain as a secondary homepage.
我想声明一个特定的静态子域作为辅助主页。
constraints(Subdomain) do
match '/' => 'static_pages#secondary_home'
end
root to: 'static_pages#home'
lib/subdomain.rb LIB / subdomain.rb
class Subdomain
def self.matches?(request)
request.subdomain.present? && request.subdomain.eql? "secondaryhome"
end
end
so now I expect only secondaryhome.lvh.me:3000 to point to my secondary homepage. 所以现在我希望只有secondaryhome.lvh.me:3000指向我的辅助主页。 (lvh.me is and external domain that points to localhost) .However, any subdomain I have (for instance abc.lvh.me:3000) seems to be pointing to the secondary home, while i want it to default to my primary root.
(lvh.me是指向本地主机的外部域)。但是,我拥有的任何子域(例如abc.lvh.me:3000)似乎都指向辅助主目录,而我希望它默认为我的主根目录。 What should i do?
我该怎么办?
We've done the equivalent of this: 我们已经做到了这一点:
#config/routes.rb
constraints({ subdomain: "secondaryhome" }) do
match '/' => 'static_pages#secondary_home'
end
This sets a route for lvh.me:3000 with constraint { subdomain: "secondaryhome" }
- only that should work 这为
lvh.me:3000 with constraint { subdomain: "secondaryhome" }
设置了一个lvh.me:3000 with constraint { subdomain: "secondaryhome" }
的路由-仅该路由有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.