Rails 3.x TLD长度

8 subdomain dns ruby-on-rails tld

在Rails的配置中,我可以将TLD长度全局设置为2(co.uk作为示例),以便request.domain和request.subdomain正确解析而无需传递选项吗?

也就是说,request.domain(2),默认情况下Rails似乎默认设置为1,并且能够全局更改它是有意义的,但是,无法在文档中找到任何内容.

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

小智 11

在config/environments/production.rb文件中添加以下行:

config.action_dispatch.tld_length = 2
Run Code Online (Sandbox Code Playgroud)

config.action_dispatch.tld_length设置应用程序的TLD(顶级域)长度.默认为1.

http://guides.rubyonrails.org/configuring.html


jde*_*eno 8

在Rails 3.1中,您可以设置:

ActionDispatch::Http::URL.tld_length = 2
Run Code Online (Sandbox Code Playgroud)

  • 我看到有一个config.action_dispatch.tld_length设置ActionDispatch :: Http :: URL.tld_length我会看3.1,看看助手是否使用它. (2认同)

Jon*_*röm 2

对于 Rails 3.0.9 及更低版本,没有这样的配置,因为 的来源domain是:

# 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
Run Code Online (Sandbox Code Playgroud)

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