validation_reflection icon indicating copy to clipboard operation
validation_reflection copied to clipboard

Rails 3.2 issue with undefined method 'write_inheritable_array'

Open JDutil opened this issue 13 years ago • 10 comments

/Users/JD/.rvm/gems/ruby-1.9.2-p290@ab_reps/gems/activerecord-3.2.0.rc2/lib/active_record/dynamic_matchers.rb:50:in `method_missing': undefined method `write_inheritable_array' for #<Class:0x007f847e5442f0> (NoMethodError)
    from /Users/JD/.rvm/gems/ruby-1.9.2-p290@ab_reps/gems/validation_reflection-1.0.0/lib/validation_reflection.rb:82:in `block in remember_validation_metadata'
    from /Users/JD/.rvm/gems/ruby-1.9.2-p290@ab_reps/gems/validation_reflection-1.0.0/lib/validation_reflection.rb:81:in `each'
    from /Users/JD/.rvm/gems/ruby-1.9.2-p290@ab_reps/gems/validation_reflection-1.0.0/lib/validation_reflection.rb:81:in `remember_validation_metadata'
    from /Users/JD/.rvm/gems/ruby-1.9.2-p290@ab_reps/gems/validation_reflection-1.0.0/lib/validation_reflection.rb:60:in `block in validates_presence_of_with_reflection'
    from /Users/JD/.rvm/gems/ruby-1.9.2-p290@ab_reps/gems/validation_reflection-1.0.0/lib/validation_reflection.rb:91:in `ignoring_subvalidations'
    from /Users/JD/.rvm/gems/ruby-1.9.2-p290@ab_reps/gems/validation_reflection-1.0.0/lib/validation_reflection.rb:58:in `validates_presence_of_with_reflection'

JDutil avatar Jan 06 '12 00:01 JDutil

I have the exact same issue...

Stefano1990 avatar Jan 15 '12 04:01 Stefano1990

+1

ndemoreau avatar Jan 24 '12 10:01 ndemoreau

+1. If it helps, I updated from 3.0.9 -> 3.1 -> 3.2 Thanks!

marcoam avatar Jan 27 '12 08:01 marcoam

Try changing

    def remember_validation_metadata(validation_type, *attr_names)
      configuration = attr_names.last.is_a?(Hash) ? attr_names.pop : {}
      attr_names.each do |attr_name|
        write_inheritable_array :validations,
          [ ActiveRecord::Reflection::MacroReflection.new(validation_type, attr_name.to_sym, configuration, self) ]
      end
    end

to:

   def remember_validation_metadata(validation_type, *attr_names)
      configuration = attr_names.last.is_a?(Hash) ? attr_names.pop : {}
      self.validations ||= []
      attr_names.each do |attr_name|
        self.validations << ActiveRecord::Reflection::MacroReflection.new(validation_type, attr_name.to_sym, configuration, self)
      end
    end

and

  def self.included(base)
    return if base.kind_of?(BoilerPlate::ActiveRecordExtensions::ValidationReflection::ClassMethods)
    base.extend(ClassMethods)
  end

to

  def self.included(base)
    return if base.kind_of?(BoilerPlate::ActiveRecordExtensions::ValidationReflection::ClassMethods)
    base.extend(ClassMethods)
    base.send :class_attribute, :validations
  end

Untested, as I' still have to work through other issues with Rails 3.2 before getting it running... ;-)

ncri avatar Jan 28 '12 18:01 ncri

Okay, one more change is required to get it working (now tested ;-):

Change the reflect_on_all_validations method to

# Returns an array of MacroReflection objects for all validations in the class
def reflect_on_all_validations
  validations || []
end

ncri avatar Jan 28 '12 20:01 ncri

I'm not sure if you forgot to post some changes you made or if you didn't do the update off from master. I tried to just create a Rails 3.2 branch for a pull request and can't get the updates to work. Notably the code you want me to change away from doesn't match what you've got listed as what to change.

JDutil avatar Feb 04 '12 21:02 JDutil

Ah, sorry, I might not have been on the latest version, yes... can you figure out what needs to be changed on master from my hints? Otherwise I can look if I can.

ncri avatar Feb 04 '12 22:02 ncri

Okay, as far as i can see you only need to replace in my code:

 return if base.kind_of?(BoilerPlate::ActiveRecordExtensions::ValidationReflection::ClassMethods)

in def self.included(base) to

 return if base.kind_of?(::ValidationReflection::ClassMethods)

and

 attr_names.each do |attr_name| 

in remember_validation_metadata to

 attr_names.flatten.each do |attr_name|

to be conform with master

ncri avatar Feb 04 '12 22:02 ncri

base.send :class_attribute, :validations

Isn't working properly for me. I get:

/Users/JD/validation_reflection/lib/validation_reflection.rb:30:in `included': undefined method `class_attribute' for ValidationReflection::ClassMethods:Module (NoMethodError)
    from /Users/JD/validation_reflection/lib/validation_reflection.rb:62:in `include'
    from /Users/JD/validation_reflection/lib/validation_reflection.rb:62:in `<module:ClassMethods>'
    from /Users/JD/validation_reflection/lib/validation_reflection.rb:60:in `<module:ValidationReflection>'
    from /Users/JD/validation_reflection/lib/validation_reflection.rb:3:in `<top (required)>'
    from /Users/JD/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
    from /Users/JD/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
    from /Users/JD/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/JD/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/JD/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/JD/validation_reflection/test/validation_reflection_test.rb:17:in `<top (required)>'

That shouldn't be looking for it on: ValidationReflection::ClassMethods:Module

It should just be ValidationReflection::ClassMethods right?

JDutil avatar Feb 05 '12 03:02 JDutil

Okay, I was working on the old plugin version.

Here is the fix for master: https://github.com/redinger/validation_reflection/pull/13

ncri avatar Feb 05 '12 10:02 ncri