Ko None
2009-Aug-07 04:21 UTC
Overriding save_with_validation and alias_method_chain error
So i''m trying to override save_with_validation in activerecord validations.rb and i''m running in to problems with alias_chain method. module ActiveRecord module Validations def save_with_validation(perform_validation = true) if perform_validation && valid? || !perform_validation save_without_validation else false end end end Base.class_eval do include Validations end end Error. (loop) http://pastie.org/pastes/574901 Whats happening is that my save_with_validation is called when i call .save then because of the alias chain method its called the save_with_validation in validation.rb as save_without_validation. So I found dirty.rb is also alias_method_chain ing save so I tried this Base.class_eval do include Validations include Dirty end think this would re-alias those methods and it did something where my error is now different: SystemStackError: stack level too deep from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb:43:in `number?'' from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/dirty.rb:154:in `field_changed?'' from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/dirty.rb:132:in `write_attribute_without_dirty'' from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/dirty.rb:139:in `write_attribute'' from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:211:in `bln='' from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/base.rb:2740:in `send'' from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/base.rb:2740:in `attributes='' from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/base.rb:2736:in `each'' from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/base.rb:2736:in `attributes='' from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/base.rb:2434:in `initialize'' from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/base.rb:721:in `new'' from /Users/Kevin/Desktop/light/vendor/rails/activerecord/lib/active_record/base.rb:721:in `create'' from (irb):1 what i want to do is grab the data passed in from save like this object.save(:test) I want to grab that :test my code works when I put it right in the rails files but not in plugin as i have to override stuff. can anyone help? -- Posted via http://www.ruby-forum.com/.