# Overriding save\_with\_validation and alias\_method\_chain error

**URL:** <https://www.ruby-forum.com/t/overriding-save-with-validation-and-alias-method-chain-error/173345>\
**Category:** Rails\
**Created:** [August 7, 2009, 6:21am UTC](https://www.ruby-forum.com/t/overriding-save-with-validation-and-alias-method-chain-error/173345 "2009-08-07T06:21:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![knodi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bbce88/32.png) [@knodi](https://www.ruby-forum.com/u/knodi)\
**Post date:** [August 7, 2009, 6:21am UTC](https://www.ruby-forum.com/t/overriding-save-with-validation-and-alias-method-chain-error/173345/1 "2009-08-07T06:21:36Z")

</div>

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](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?
