[英]undefined method attr_encrypted in Rails 2.3 app
我正在维护Rails 2.3应用程序(移动到Rails 4会破坏太多事情),并尝试加密/解密密码,而不是将密码以纯文本格式保存在数据库中。
按照attr_encrypted gem的说明,我添加了
gem "attr_encrypted"
到我的Gemfile,运行捆绑安装-一切顺利。
然后,按照说明,我将新字段“ encrypted_password”迁移到表中,并在app / models / serverobj.rb中放一行:
attr_encrypted :password, :key => 'foo'
但是当我浏览那里时,我得到了这样的堆栈跟踪:
=> Booting WEBrick...
/home/art/vendor/rails/activerecord/lib/active_record/base.rb:1833:in `method_missing_without_paginate': undefined method `attr_encrypted' for #<Class:0x7f009f372200> (NoMethodError)
from /home/art/vendor/plugins/will_paginate/lib/will_paginate/finder.rb:164:in `method_missing'
from /home/art/app/models/serverobj.rb:17
...
from /home/art/config/environment.rb:70
serverobj.rb
第17行是:
attr_encrypted :password, :key => 'foo'
environment.rb
第70行是:
Rails::Initializer.run do |config|
config.load_paths += %W( #{RAILS_ROOT}/vendor/gems/ #{RAILS_ROOT}/app/exceptions/ )
啊哈! 我说过,attr_encrypted gem一定不能在load_paths中。 因此,我在/var/lib/gems/1.8/gems/
找到了attr_encrypted gem,并将其添加到environment.rb
的config.load_paths
行中。
但是我仍然得到“未定义的方法attr_encrypted”。
我没办法尝试了。 有任何想法吗?
我相信您的问题是attr_encrypted
gem(在当前版本中)与Rails 2.3不兼容。 根据您的评论,Bundler正在跳过加载gem,因为这样做时会引发错误NameError: uninitialized constant ActiveRecord::VERSION
,这就是为什么您的应用程序中没有gem功能的原因。
但是,该宝石最初于2009年创建,因此它的较旧版本可能会与您的Rails兼容。 尝试更新您的Gemfile以使用旧版本之一 ,例如:
gem 'attr_encrypted', '1.0.8'
看看效果是否更好。 API可能会在版本之间变化,因此请确保参考最终使用的版本的相应README文件 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.