This project is archived and is in readonly mode.

#5252 open
gucki

ActiveModel Naming should take care of anonymous classes

Reported by gucki | July 30th, 2010 @ 04:14 PM | in 3.0.6

When trying to use the ActiveModel Validations together with sequel like

class Message < Sequel::Model
  include ActiveModel::Validations
  validates :text, :presence => true, :length => { :within => 1..10000 }
end

I get the following error: ArgumentError (interning empty string).

activemodel (3.0.0.rc) lib/active_model/naming.rb:27:in to_sym' 
activemodel (3.0.0.rc) lib/active_model/naming.rb:27:inhuman'
activemodel (3.0.0.rc) lib/active_model/naming.rb:26:in map' 
activemodel (3.0.0.rc) lib/active_model/naming.rb:26:inhuman'
activemodel (3.0.0.rc) lib/active_model/errors.rb:313:in generate_message' 
activemodel (3.0.0.rc) lib/active_model/errors.rb:188:inadd'
activemodel (3.0.0.rc) lib/active_model/errors.rb:223:in add_on_blank' 
activemodel (3.0.0.rc) lib/active_model/errors.rb:221:ineach'
activemodel (3.0.0.rc) lib/active_model/errors.rb:221:in add_on_blank' 
activemodel (3.0.0.rc) lib/active_model/validations/presence.rb:9:invalidate'
activesupport (3.0.0.rc) lib/active_support/callbacks.rb:309:in send' 
activesupport (3.0.0.rc) lib/active_support/callbacks.rb:309:in_callback_before_47'
activesupport (3.0.0.rc) lib/active_support/callbacks.rb:409:in _run_validate_callbacks' 
activemodel (3.0.0.rc) lib/active_model/validations.rb:201:inrun_validations!'
activemodel (3.0.0.rc) lib/active_model/validations.rb:168:in valid?' /home/gucki/.rvm/gems/ree-1.8.7-2010.01@rails3/bundler/gems/sequel-a54e149/lib/sequel/model/base.rb:957:insave' ...

Jeremy (Sequel maintainer says): This looks like an ActiveModel bug, as they shouldn't be attempting to call to_sym on an empty string. Basically, they should be checking for anonymous classes and they aren't.

A quick fix is to modify ActiveModel::Naming from

  defaults = @klass.lookup_ancestors.map do |klass|
    klass.model_name.underscore.to_sym
  end

to

  defaults = @klass.lookup_ancestors.map do |klass|
    next if klass.name==""
    klass.model_name.underscore.to_sym
  end.compact

If this fix is okay, I can create a patch for it.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages