I use the acts_as_secure plugin to encrypt certain sensitive fields in a model in my Rails app. I recently added an observer for that same model to log certain actions on the model for reporting purposes. I've got an irritating interaction between rake and the observer now that I can't sort out.
With the observer not commented out in environment.rb ... [ In an effort to not look stupid in public the author went and did some more spelunking at this point and actually came up with a solution. In the interest of education this post will continue as originally intended. ] With the observer not commented out in environment.rb every time I try to run rake db:migrate (or any rake task) I get this error: `method_missing': undefined method `symbolize_keys' for nil:NilClass (NoMethodError) Tracing into the error dump I found the offending line is in the acts_as_secure MasterCryptoProvider: CONFIG = YAML.load_file(RAILS_ROOT + '/config/crypto.yml') [ENV['RAILS_ENV']].symbolize_keys My conclusion is that due to the order in which things are initialized by rake the RAILS_ENV variable isn't set before MasterCryptoProvider tries to read its config file. My initial solution was to comment out the line in the environment file or to add RAILS_ENV='development' in front of the rake call, and though this works both seem klutzy. Why is this happening? Is there a smart way to prevent it? The solution I came up with as I started to write this was to add || 'development' to the MasterCryptoProvider code so that it will default to development if RAILS_ENV is nil. But is there a better way? Thanks, Chris -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby
