Missing require 'active_record' in encrypted_strings.rb?
Reported by Brandon Valentine | July 6th, 2008 @ 07:29 PM
In several of the encryptor modules you call cattr_accessor which is an ActiveRecord method. On my system I get a dependency error when including encrypted_attributes (which includes encrypted_strings) into a Rails app unless I add require 'active_record' to encrypted_strings.rb.
I am running Rails 2.0.2 on Ruby 1.8.6 on Mac OS X 10.5.4. Rails is installed via gem as is encrypted_strings (and encrypted_attributes). I have the following in my environment.rb:
require 'rubygems'
require 'encrypted_attributes'
If I try to run ./script/console (or any other Rails command) I get:
% ./script/console
Loading development environment (Rails 2.0.2)
/Library/Ruby/Gems/1.8/gems/encrypted_strings-0.0.4/lib/encrypted_strings/symmetric_encryptor.rb:44:NoMethodError: undefined method `cattr_accessor' for PluginAWeek::EncryptedStrings::SymmetricEncryptor:Class
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:88:NoMethodError: undefined method `cattr_accessor' for ActionController::Dispatcher:Class
Adding require 'active_record' to the top of encrypted_strings.rb fixes it for me. Not sure if this is the correct fix, but it does seem to be working.
Comments and changes to this ticket
-
Aaron Pfeifer July 6th, 2008 @ 08:21 PM
At what point are you loading the plugin during the initialization process? I agree that there's an assumption that cattr_accessor is available from the active_support library and that's definitely something worth investigating. However, if you use the following in your environment configuration, does it fix things?
Rails::Initializer.run do |config| ... config.gem 'encrypted_attributes' ... endThe difference here is that these gem dependencies are loaded after the Rails environment has been loaded in the same way the plugins are.
-
Brandon Valentine July 6th, 2008 @ 11:13 PM
Indeed that did fix the problem. Thanks for the reply, Aaron. I'm a bit new to Rails and hadn't run across the config.gem syntax anywhere yet. =)
-
Aaron Pfeifer July 7th, 2008 @ 09:57 PM
- → State changed from new to resolved
No problem. Thanks for bringing to my attention some rogue dependencies on active_support. I've since spent time ensuring that the "Ruby" extensions like encrypted_strings only rely on Ruby and not on third-party libraries like active_support.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Provides dead-simple string encryption/decryption syntax
