While upgrading one of my Rails 2.3 apps to Rail 3, I came across a few issues when using subdomains with a localhost domain. I have a route like so:-

 root :to => 'controller#page', :constraints => {:subdomain => "subdomain1"}

I had a test subdomain set-up in my /etc/hosts file as usual. For instance, here is the first line in my /etc/hosts file:-

 127.0.0.1     subdomain1.localhost

So, if I request the url http://subdomain1.localhost:3000, Rails 3 treats "subdomain1.localhost" as the domain. In other words, it is treating "localhost" as the TLD.

To fix this I changed my test subdomain, in the /etc/hosts file, to have a TLD, like so:-

 127.0.0.1     subdomain1.localhost.local

And hey presto, as if by magic, it now works.

UPDATE: Changed TLD to .local (makes more sense)