Calling “sanitize” method on anything causes a missing method error in Rails 3 with Collective Idea’s Money Gem
sanitize "trololo"
=>
undefined method `id2name' for {:instance_writer=>false}:Hash
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:7:in `block in cattr_reader'
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:5:in `each'
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:5:in `cattr_reader'
collectiveidea-money (1.7.4) lib/support/cattr_accessor.rb:54:in `cattr_accessor'
actionpack (3.2.8) lib/action_controller/vendor/html-scanner/html/sanitizer.rb:48:in `<class:LinkSanitizer>'
actionpack (3.2.8) lib/action_controller/vendor/html-scanner/html/sanitizer.rb:47:in `<module:HTML>'
actionpack (3.2.8) lib/action_controller/vendor/html-scanner/html/sanitizer.rb:5:in `<top (required)>'
actionpack (3.2.8) lib/action_view/helpers/sanitize_helper.rb:174:in `white_list_sanitizer'
actionpack (3.2.8) lib/action_view/helpers/sanitize_helper.rb:60:in `sanitize'
Has anyone experienced this error before?
After digging around in the source code I found this: The money gem defines the
cattr_accessorhelper methods (see in file YOUR_GEM_DIR/collectiveidea-money-1.7.4/lib/support/cattr_accessor.rb) as does active_support (see in file YOUR_GEM_DIR/activesupport-3.2.8/lib/active_support/core_ext/class/attribute_accessors.rb).Unfortunately, the implementation in the money gem differs from the one in active_support. And in your case, the money gem has been loaded after active_support and overwrote the *good* active_support implementation.
You can “fix” it by making sure that the money gem is loaded before active_support. If you post more details about your application, I can tell you how to do that…
However, the money gem seems to be pretty outdated, so I suggest you replace it with something that is more recent and actively maintained…