加入
class User < ActiveRecord::Base
has_secure_password
end
使用
#如果password != password_confirmation,调用save,返回false
user = User.new(name: 'david', password: '123', password_confirmation: '123')
user.save
user.authenticate('123') #true
user.authenticate('xuji') #false
User.find_by(name: 'david').try(:authenticate, 'notright') #false
User.find_by(name: 'david').try(:authenticate, '123') #true