Rails 3.x TLD长度 [英] Rails 3.x TLD length

查看:147
本文介绍了Rails 3.x TLD长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Rails的配置中有些地方可以将TLD长度全局设置为2(以co.uk为例),因此request.domain和request.subdomain正确解析,而无需传递选项?

Is there some where in Rails's configuration where I can globally set the TLD length to 2 (co.uk as an example) so request.domain and request.subdomain parse correctly without having to pass options?

那就是request.domain(2),默认情况下,Rails似乎设置为1,所以能够在全局范围内进行更改是有意义的,但是无法在文档中找到任何东西。

That is, request.domain(2), by default Rails seems to be set to 1 by default and it makes sense to be able to change this globally, however, haven't been able to find anything in the documentation.

是否存在这样的配置选项?

Does such a configuration option exist?

推荐答案

对于Rails 3.0.9及更低版本,由于的来源是:

For Rails 3.0.9 and below, there's no such configuration since the source of domain is:

# File actionpack/lib/action_dispatch/http/url.rb, line 78
def domain(tld_length = 1)
  return nil unless named_host?(host)

  host.split('.').last(1 + tld_length).join('.')
end

资料来源: http://apidock.com/rails/v3.0.9/ActionDispatch/Http/URL/domain

这篇关于Rails 3.x TLD长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆