I'm maintaining a Rails 2.3 app (moving to Rails 4 broke too many things), and trying to encrypt/decrypt a password instead of saving it plain-text in the database.
Following the instructions for the attr_encrypted gem, I added
gem "attr_encrypted"
to my Gemfile, ran bundle install - all happy.
Then, per instructions, I migrated in a new field, encrypted_password, to the table, and put one line in app/models/serverobj.rb:
attr_encrypted :password, :key => 'foo'
But when I browse there, I get a stack trace like this:
=> 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
, line 17 is:
attr_encrypted :password, :key => 'foo'
environment.rb
, line 70 is:
Rails::Initializer.run do |config|
config.load_paths += %W( #{RAILS_ROOT}/vendor/gems/ #{RAILS_ROOT}/app/exceptions/ )
Aha! I said, the attr_encrypted gem must not be in the load_paths.
So I found the attr_encrypted gem in /var/lib/gems/1.8/gems/
, and added that to the config.load_paths
line in environment.rb
.
But I still get 'Undefined method attr_encrypted'.
I've run out of things to try. Any ideas?
class Foo; attr_encrypted :bar; end
raise the same error? Doesrequire 'attr_encrypted'
work? Does the first snippet work after doing so? – Robert Nubel