mbleigh / subdomain-fu

A new plugin approach to attempting to solve the usage of subdomains in linking and routing in Rails projects.
http://rdoc.info/projects/mbleigh/subdomain-fu
Other
586 stars 118 forks source link

current_domain returns wrong domain #13

Open alPacino opened 14 years ago

alPacino commented 14 years ago

Hi!

Helper current_domain returns wrong domain. Ex.: We have 'sub.domain.com.local'. For this case we, of course, set TLD to 2. and expect that current_domain will return 'domain.com.local', but it returns 'com.local' instead.

The cause is here:

diff --git a/vendor/plugins/subdomain-fu/lib/subdomain-fu.rb b/vendor/plugins/subdomain-fu/lib/subdomain-fu.rb
index 7b4a9da..9c8d7d4 100644
--- a/vendor/plugins/subdomain-fu/lib/subdomain-fu.rb
+++ b/vendor/plugins/subdomain-fu/lib/subdomain-fu.rb
@@ -140,8 +140,10 @@ module SubdomainFu
   #Enables subdomain-fu to more completely replace DHH's account_location plugin
   def self.current_domain(request)
     domain = ""
-    domain << request.subdomains[1..-1].join(".") + "." if request.subdomains.length > 1
-    domain << request.domain + request.port_string
+    subdomains = request.subdomains(SubdomainFu.tld_size)
+    domain << subdomains[1..-1].join(".") + "." if subdomains.length > 1
+    domain << request.domain(SubdomainFu.tld_size) + request.port_string
+    domain
   end

   module Controller

Here you used request.subdomains and request.domain w/o TLD param. By default it is set to 1. So, if tld_size is set to 1 in development.rb, for instance, everything works fine. But for example mentioned below this doesn't work as expected. I've just defined TLD param for calling request.subdomains and request.domain.

P.S. SubdomainFu.tld_size = X doesn't work for me. I get

undefined method `tld_size=' for SubdomainFu:Module