【问题标题】:How to setup specific subdomain for rails routes?如何为 Rails 路由设置特定的子域?
【发布时间】:2014-06-11 02:34:55
【问题描述】:

我正在尝试在 rails 中为我的网站设置一个子域。我跟着rails cast来做这件事。 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 是指向 localhost 的外部域)。但是,我拥有的任何子域(例如 abc.lvh.me:3000)似乎都指向辅助主页,而我希望它默认为我的主根.我该怎么办?

【问题讨论】:

    标签: ruby-on-rails ruby subdomain


    【解决方案1】:

    我们已经完成了类似的操作:

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

    这为lvh.me:3000 with constraint { subdomain: "secondaryhome" } 设置了一条路线 - 只有这样才能工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      • 2013-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多