我正在维护一个 Rails 2.3 应用程序(迁移到 Rails 4 破坏了太多东西),并尝试加密/解密密码而不是将其以纯文本形式保存在数据库中。
按照 attr_encrypted gem 的说明,我添加了
gem "attr_encrypted"
到我的 Gemfile,运行 bundle install - 一切都很开心。
然后,按照说明,我将新字段 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 中。所以我在 中找到了 attr_encrypted gem /var/lib/gems/1.8/gems/
,并将其添加config.load_paths
到environment.rb
.
但我仍然得到“未定义的方法 attr_encrypted”。
我已经没有东西可以尝试了。有任何想法吗?