Ok, I did it.
Edited config.authentication_keys in devise.rb as
config.authentication_keys = [ :login, :account_id ]
I also created a hidden field to include account_id in the login form
<%= f.hidden_field :account_id, :value => @account.id %>
Here, @account holds the account associated with the current subdomain.
And added the following protected method to user.rb to override the find_for_database_authentication class method
protected def self.find_for_database_authentication(warden_conditions) conditions = warden_conditions.dup login = conditions.delete(:login) account_id = conditions.delete(:account_id) where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).where("account_id = ?", account_id).first end
If there is a better solution, then feel free to comment on the guys ..
Hurrah!
source share