diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-18 17:19:15 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-18 17:19:15 +0000 |
commit | a7532f9d5f47cf17c18a17dccff2a6d317d8254e (patch) | |
tree | 96c58c95a5977a45a67130227ff2ef82046a12bf /actionpack/lib | |
parent | b09829354f4699941824f53903f4a8743fa98bd5 (diff) | |
download | rails-a7532f9d5f47cf17c18a17dccff2a6d317d8254e.tar.gz rails-a7532f9d5f47cf17c18a17dccff2a6d317d8254e.tar.bz2 rails-a7532f9d5f47cf17c18a17dccff2a6d317d8254e.zip |
Added Request#domain (returns string) and Request#subdomains (returns array).
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@213 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rwxr-xr-x | actionpack/lib/action_controller/request.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 9eb0b04ef0..e9ab3cad90 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -50,6 +50,20 @@ module ActionController return env['REMOTE_ADDR'] end + # Returns the domain part of a host, such as rubyonrails.org in "www.rubyonrails.org". You can specify + # a different <tt>tld_length</tt>, such as 2 to catch rubyonrails.co.uk in "www.rubyonrails.co.uk". + def domain(tld_length = 1) + host.split(".").last(1 + tld_length).join(".") + end + + # Returns all the subdomains as an array, so ["dev", "www"] would be returned for "dev.www.rubyonrails.org". + # You can specify a different <tt>tld_length</tt>, such as 2 to catch ["www"] instead of ["www", "rubyonrails"] + # in "www.rubyonrails.co.uk". + def subdomains(tld_length = 1) + parts = host.split(".") + parts - parts.last(1 + tld_length) + end + def request_uri env["REQUEST_URI"] end |