Virtual attribute for authenticating by either username or email This is in addition to a real persisted field like ‘username’
allow login via either username or email address
# File app/models/user.rb, line 18 def self.find_first_by_auth_conditions(warden_conditions) conditions = warden_conditions.dup if login = conditions.delete(:login) where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first else where(conditions).first end end