我在旧数据库方面遇到了一些稍微棘手的问题。如果我简单地将数据库中的“password”列名称更改为“encrypted_password”,一切似乎都工作正常;但是,我需要将数据库保留在适当的位置。
所以我决定使用
alias_attribute :encrypted_password, :password
现在我在控制台中收到“堆栈级别太深”错误。
我的用户模型:
class User < ActiveRecord::Base
require "digest/sha1"
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :encryptable, :encryptor => :old_cakephp_auth
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
has_many :events
before_create :add_default_values
#alias_attribute :created_at, :created
#alias_attribute :updated_at, :updated
alias_attribute :encrypted_password, :password
def add_default_values
self.created = Time.now
self.updated = Time.now
self.image = ""
self.name = self.email.split("@").first
#make normal user
self.role_id = 2
self.username = self.email.split("@").first + rand(100000000000000).to_s
self.website = ""
end
def valid_password?(password)
return false if encrypted_password.blank?
Devise.secure_compare(Digest::SHA1.hexdigest(self.password_salt+password), self.encrypted_password)
end
end
想法?谢谢!!! :)
最佳答案
我想这是由于设计保留了单词password
供自己使用(并且它反过来调用encrypted_password
。尝试将其重命名为pword
并查看错误是否仍然出现。如果没有出现,则您必须找到另一个名称来调用别名密码。
我应该说这只是一个假设。如果有帮助请告诉我。
关于ruby-on-rails - alias_attribute 和 devise 导致堆栈级别太深错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9882099/