[英]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.