Sanitize helper causing an error in Money gem in Rails 3 - ruby-on-rails

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_accessor helper 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...

Related

Attachments in ActionMailbox/InboundEmails - unpermitted parametres

I'm trying to test how ActionMailbox works on localhost using:
http://localhost:5000/rails/conductor/action_mailbox/inbound_emails
It works fine until I try to add an attachment. Then I receive an error:
ActionController::UnpermittedParameters (found unpermitted parameter: :attachments):
actionpack (6.1.3.1) lib/action_controller/metal/strong_parameters.rb:973:in `unpermitted_parameters!'
actionpack (6.1.3.1) lib/action_controller/metal/strong_parameters.rb:604:in `permit'
actionmailbox (6.1.3.1) app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb:23:in `new_mail'
actionmailbox (6.1.3.1) app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb:17:in `create'
I was trying to add :attachments to permitted parameters in line 23 of inbound_emails_controller.rb but with no effect :/
I have no idea why it doesn't work and nobody else found this bug :(

Rails 3 App on ruby 1.9.2 mysteriously missing Base64 methods

Trying to implement HTTP digest authentication in a Rails ApplicationController but am getting an enexpected exception on my call to authenticate_or_request_with_http_digest(REALM):
undefined method `unpack' for nil:NilClass
Top of stacktrace:
/Users/chadmiko/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/base64.rb:58:in
`decode64' actionpack (3.2.8)
lib/action_controller/metal/http_authentication.rb:301:in
`validate_nonce' actionpack (3.2.8)
lib/action_controller/metal/http_authentication.rb:188:in
`validate_digest_response' actionpack (3.2.8)
lib/action_controller/metal/http_authentication.rb:179:in
`authenticate' actionpack (3.2.8)
lib/action_controller/metal/http_authentication.rb:168:in
`authenticate_with_http_digest' actionpack (3.2.8)
lib/action_controller/metal/http_authentication.rb:163:in
`authenticate_or_request_with_http_digest'
Other outputs (note: I'm using rvm and have created a project gemset):
chadmiko [ ~/Documents/Projects/msa-web ]$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
chadmiko [ ~/Documents/Projects/msa-web ]$ rails --version
Rails 3.2.8
Also, if I startup irb:
chadmiko [ ~/Documents/Projects/msa-web ]$ irb
1.9.2-p290 :001 > require 'base64'
=> true
Feel like there's a simple solution here but I'm just missing it. Any tips would be appreciated. Thanks.

Enabling cache_classes causes undefined method `increment_counter' for ActiveRecord::Relation:Class

After upgrade to Rails 3.0.10 I'm getting strange error if I set config.cache_classes=true
NoMethodError (undefined method increment_counter' for ActiveRecord::Relation:Class):
activerecord (3.0.10) lib/active_record/associations.rb:1553:inbelongs_to_counter_cache_after_create_for_form'
activesupport (3.0.10) lib/active_support/callbacks.rb:424:in _run_create_callbacks'
activerecord (3.0.10) lib/active_record/callbacks.rb:277:increate'
activerecord (3.0.10) lib/active_record/persistence.rb:257:in create_or_update'
activerecord (3.0.10) lib/active_record/callbacks.rb:273:increate_or_update'
activesupport (3.0.10) lib/active_support/callbacks.rb:444:in _run_save_callbacks'
activerecord (3.0.10) lib/active_record/callbacks.rb:273:increate_or_update'
activerecord (3.0.10) lib/active_record/persistence.rb:60:in save!'
activerecord (3.0.10) lib/active_record/validations.rb:49:insave!'
activerecord (3.0.10) lib/active_record/attribute_methods/dirty.rb:30:in `save!'
...
I'm saving Answer model which has belongs_to relation with counter cache:
belongs_to :form, :counter_cache => true
Strangest thing is that after server restart first save works fine and after that I start getting such exceptions.
Maybe someone could advise where I could start digging for a cause?
The problem was caused by outdated acts_as_taggable_on_steroids gem which was causing class cache issues with Rails3. Switched to acts-as-taggable-on gem - problem solved.

Is there any way to avoid encoding error when using ActionMailer with Ruby 1.8.7

I keep getting the following error when sending a simple e-mail via ActionMailer in Rails:
NoMethodError: undefined method `encode!' for "Hello":String
This is triggered whenever the following is run:
def hello_world_email()
mail( :from => "me",
:to => "you,
:subject => "Hello World"
)
end
From researching this, it looks like it's caused by the differences between Ruby 1.8.7 and 1.9.*, which has built-in character encoding support.
Is there any way of getting ActionMailer to work with Ruby 1.8.7 and avoid this issue? (I can upgrade Ruby on my machine, but I can't do the same for everyone else working on the project). Given that the whole of Rails 3.0.9 (of which ActionMailer is a part) is meant to work with Ruby 1.8.7, I keep thinking that there must be a way...
Note: My exact version of Ruby is ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] (pre-installed on OSX).
You may have an issue with using Ruby 1.8 and having a constant Encoding defined by a gem.
For example we found an issue with a class that was including REXML at a global scope.
The line in question in the library was:
value.encode!(charset) if defined?(Encoding) && charset
This is checking for a global constant called Encoding. (Which could be defined in any gem at global scope.) Our problem was actually the include which then made REXML::Encoding available everywhere as Encoding. You could try grepping or acking your codebase for "module Encoding" or "class Encoding".
Hope this helps.
The stack trace below defines the problem.
NoMethodError: undefined method `encode!' for "Generate":String
mail (2.2.19) lib/mail/fields/unstructured_field.rb:169:in `encode'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:138:in `fold'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:108:in `wrapped_value'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:70:in `do_encode'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:52:in `encoded'
mail (2.2.19) lib/mail/field.rb:123:in `send'
mail (2.2.19) lib/mail/field.rb:123:in `method_missing'
mail (2.2.19) lib/mail/header.rb:190:in `encoded'
mail (2.2.19) lib/mail/header.rb:189:in `each'
mail (2.2.19) lib/mail/header.rb:189:in `encoded'
mail (2.2.19) lib/mail/message.rb:1708:in `encoded'
actionmailer (3.0.10) lib/action_mailer/base.rb:445:in `set_payload_for_mail'
actionmailer (3.0.10) lib/action_mailer/base.rb:425:in `deliver_mail'
activesupport (3.0.10) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.10) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.10) lib/active_support/notifications.rb:52:in `instrument'
actionmailer (3.0.10) lib/action_mailer/base.rb:424:in `deliver_mail'
mail (2.2.19) lib/mail/message.rb:230:in `deliver'
I had the same error, when trying to test my devise confirmation emails. Weird thing was, running the test isolated did not throw this exception. Running the whole stack did. After doing a binary search, i found, that one of my specs used REXML to parse some content.
require 'spec_helper'
require 'rexml/document'
include REXML
doc = Document.new(response.body)
I dont't know, why i included REXML, presumably, because i wanted to save the REXML:: in front of Document. But changing the code to this fixed the problem:
require 'spec_helper'
require 'rexml/document'
doc = REXML::Document.new(response.body)
if you happen to use code like this somewhere, this may fix this encode! issue with ruby 1.8.7
I found the issue to be with the mailer gem, changing to 2.2.13 fixed it for me.

no such file to load -- active_support/core_ext (LoadError)

In my rails 2.3.8 app running in windows 7, getting the following error when attempting to start the server:
D:\app1>ruby script/server
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- active_support/core_ext (LoadError)
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from D:/app1/vendor/rails/activesupport/lib/active_support.rb:56
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from D:/app1/vendor/rails/railties/lib/commands/server.rb:1
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:3
In the custom require file block below... line 36 is "gem_original_require path"
def require(path) # :doc:
gem_original_require path
rescue LoadError => load_error
if load_error.message =~ /#{Regexp.escape path}\z/ and
spec = Gem.searcher.find(path) then
Gem.activate(spec.name, "= #{spec.version}")
gem_original_require path
else
raise load_error
end
end
gem list as follows:
actionmailer (2.3.8)
actionpack (2.3.8)
activerecord (2.3.8)
activeresource (2.3.8)
activesupport (2.3.8)
builder (3.0.0)
calendar_date_select (1.16.1)
cgi_multipart_eof_fix (2.5.0)
gem_plugin (0.2.3)
google4r-checkout (1.0.6.1)
i18n (0.5.0)
liquid (2.2.2)
money (3.5.5)
mongrel (1.1.5 x86-mingw32)
mysql (2.8.1 x86-mingw32)
rack (1.1.0)
rails (2.3.8)
rake (0.8.7)
rmagick (2.12.0 mswin32)
Looked around with portions of the error, but I'm not quite sure where to start.
Just looking at the stack trace ... it looks like your application is on drive "D" and the ruby files are on drive "C".
Maybe when its performing the require
filenames = Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"].sort.map do |path|
File.basename(path, '.rb')
end
its requiring that path on "D" when it should be on "C". That's my best guess. Good luck.
create a file name
core_ext.rb
in the
C:\Ruby\lib\ruby\gems\1.8\gems\activesupport-2.3.8\lib\active_support
and edit add the content to the following lines
filenames = Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"].sort.map do |path|
File.basename(path, '.rb')
end
# deprecated
filenames -= %w(blank)
filenames.each { |filename| require "active_support/core_ext/#{filename}" }

Resources