views:

93

answers:

2

Out of the box, the devise gem asks for a user's email address and uses that to sign in (authenticate).

This railscast, "Customizing Devise", describes clearly how one can authenticate with a username in lieu of an email. How would one configure devise to try to authenticate against two different columns, either username OR email?

+1  A: 

You just need define the method find_for_database_authentication(conditions). By example, with monogid I do that :

  def self.find_for_database_authentication(conditions)
    self.where({ :login => conditions[:login] }).first || self.where({ :email => conditions[:login] }).first
  end
shingara
A: 

Ah, sorry, I didn't google sufficiently. There's an answer on the devise wiki: "Log in using login or mail"

Also, this question was already asked and answered on stackoverflow here: "Sign in with username OR email"

There's a further blog discussioon that uses the self.find_for_authentication method which is Rails 2.x compatible.

Purplejacket