Open JDutil opened 12 years ago
I have the exact same issue...
+1
+1. If it helps, I updated from 3.0.9 -> 3.1 -> 3.2 Thanks!
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... ;-)
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
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.
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.
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
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?
Okay, I was working on the old plugin version.
Here is the fix for master: https://github.com/redinger/validation_reflection/pull/13