8

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

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

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

4

3 回答 3

12

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

config.action_dispatch.tld_length = 2

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

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

于 2013-04-12T18:41:51.553 回答
8

在 Rails 3.1 中,您可以设置:

ActionDispatch::Http::URL.tld_length = 2
于 2011-08-16T14:25:57.787 回答
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

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

于 2011-08-16T14:21:57.937 回答