我在forget password.
上遇到此错误如何修复它。我想定制它。我需要通过email
以及username
重置密码。
我的模型如下
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
belongs_to :role
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :confirmable, :lockable, :validatable, :authentication_keys => [:login]
# validates_uniqueness_of :username
# validates_presence_of :username
after_create :create_profile
attr_accessor :login
def create_profile
if self.role.name == "student"
Student.create :user_id => self.id
elsif self.role.name == "company"
Company.create :user_id => self.id
else
University.create :user_id => self.id
end
end
def self.find_for_database_authentication(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
end