Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 3.2 issue with undefined method 'write_inheritable_array' #12

Open
JDutil opened this issue Jan 6, 2012 · 10 comments
Open

Rails 3.2 issue with undefined method 'write_inheritable_array' #12

JDutil opened this issue Jan 6, 2012 · 10 comments

Comments

@JDutil
Copy link

JDutil commented Jan 6, 2012

/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'
@Stefano1990
Copy link

I have the exact same issue...

@ndemoreau
Copy link

+1

@marcoam
Copy link

marcoam commented Jan 27, 2012

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

@ncri
Copy link

ncri commented Jan 28, 2012

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
Copy link

ncri commented Jan 28, 2012

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

@JDutil
Copy link
Author

JDutil commented Feb 4, 2012

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.

@ncri
Copy link

ncri commented Feb 4, 2012

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
Copy link

ncri commented Feb 4, 2012

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

@JDutil
Copy link
Author

JDutil commented Feb 5, 2012

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?

@ncri
Copy link

ncri commented Feb 5, 2012

Okay, I was working on the old plugin version.

Here is the fix for master: #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants