加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何从url获取子域值?

发布时间:2020-12-16 20:28:43 所属栏目:百科 来源:网络整理
导读:如何在rails中获得子域值,是否有内置的方法来做到这一点? 例如 test123.example.com 我想要test123的一部分url. 解决方法 Rails 3.0具有内置的此功能,您可以从request.subdomain访问子域. 您也可以根据子域路由: class SupportSubdomain def self.matches?
如何在rails中获得子域值,是否有内置的方法来做到这一点?

例如

test123.example.com

我想要test123的一部分url.

解决方法

Rails 3.0具有内置的此功能,您可以从request.subdomain访问子域.

您也可以根据子域路由:

class SupportSubdomain
  def self.matches?(request)
    request.subdomain == "support"
  end
end

Basecamp::Application.routes do
  constraints(SupportSubdomain) do
    match "/foo/bar",:to => "foo#bar"
  end
end

如果你使用2.3,你需要使用一个插件,如subdomain-fu.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读