Today I came across a rather weird phenomenon. When developing a Rails app in which every user has his own subdomain, and trying to use Devise to do it, I encountered that also subdomains not registered whatsoever would route to the root page. So, for example, even if there was no (explicit) subdomain, it would route me to the main application page. Maybe this has to do with my particular setup? I also tried with a new Rails project, but I got the same result. Anyone able to clarify this for me? Railscasts didn't do the trick.
Also, right now I'm using WEBrick, even though that's not what I'll be using in production, and I'm using the domain lvh.me to access the subdomains.
Thanks for the help.
EDIT: Here's my routes.rb file:
Rails.application.routes.draw do
devise_for :users
root 'static_page#index'
end
I followed this guide from the Devise wiki: https://github.com/plataformatec/devise/wiki/How-to:-Scope-login-to-subdomain
So what I did was I removed the uniqueness of the email through a migration, and next I added :subdomain to request_keys as follows:
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :timeoutable, request_keys: [:subdomain]
Then I went on to override the "find_for_authentication" function, as per the following:
def self.find_for_authentication(conditions={})
conditions[:account_id] = Account.find_by_subdomain(conditions.delete(:subdomain)).id
super(conditions)
end
And that just about sums it up.
EDIT: I've been messing around, and I've found the problem. The 'root' directive refers all subdomains to my domain. So if I remove the root from my routes.rb, every subdomain leads to a RouteError. I remember about needing a root somewhere in my app for Devise. So I'm not sure if this is Devise's behaviour or root's.