新手,刚刚开始学 Rails,各种问题不得其解 Question:
现在 user.rb 如下,能实现注册登录验证
class User < ActiveRecord::Base
rolify
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :invitable, :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:login]
attr_accessor :login
# Setup accessible (or protected) attributes for your model
attr_accessible :role_ids, :as => :admin
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
attr_accessible :login
validates :name, :presence => true, :length => { :in => 3..20 }, :uniqueness => true
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions).where(["lower(name) = :value OR lower(email) = :value", { :value => login.downcase }]).first
else
where(conditions).first
end
end
end