不能使用has_secure_password,password_digest错误 [英] cant use has_secure_password, password_digest error
问题描述
晚上好。我有个问题。我使用 has_secure_password
与这项事业我有一个误差未定义的方法
password_digest ='#为`
但我没有这个方法!请帮帮忙,不知道该怎么办。我读了如何解决这个问题,但它并没有帮我(
下面是我的用户模型。如果可以请帮帮忙。
类用户< ActiveRecord的::基地 attr_accessible:电子邮件,:密码:password_confirmation
has_secure_password validates_ presence_of:密码:上= GT; :创建 before_create {generate_token(:AUTH_TOKEN)} 高清send_password_reset
generate_token(:password_reset_token)
self.password_reset_sent_at = Time.zone.now
保存!
UserMailer.password_reset(个体经营).deliver
结束 高清generate_token(列)
开始
自[专栏] = SecureRandom.urlsafe_base64
结束而User.exists(列=>自[专栏])?
结束
结束
您可能已经忘记,以确保您的迁移支持用户模型对password_digest列。确保柱存在,并且它是一个字符串。如果不是这样,创建迁移到添加列
Good evening. I have a problem. i am using has_secure_password
and cause of this i have an error undefined method
password_digest=' for #`,
but i dont have this method!! Please help, dont know what to do. I read how to fix this problem but it didnt help me(
Here is my User model. Please help if you can.
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation
has_secure_password
validates_presence_of :password, :on => :create
before_create { generate_token(:auth_token) }
def send_password_reset
generate_token(:password_reset_token)
self.password_reset_sent_at = Time.zone.now
save!
UserMailer.password_reset(self).deliver
end
def generate_token(column)
begin
self[column] = SecureRandom.urlsafe_base64
end while User.exists?(column => self[column])
end
end
You may have forgotten to make sure your migration backing the user model has a column for password_digest. Make sure the column exists and that it's a string. If it doesn't, create a migration to add the column.
这篇关于不能使用has_secure_password,password_digest错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!