# ActiveRecord Warnings plugin: Problem when extending ActiveR

**URL:** <https://www.ruby-forum.com/t/activerecord-warnings-plugin-problem-when-extending-activer/110610>\
**Category:** Rails\
**Created:** [July 28, 2007, 12:45am UTC](https://www.ruby-forum.com/t/activerecord-warnings-plugin-problem-when-extending-activer/110610 "2007-07-28T00:45:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Gonzalez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/50afbb/32.png) [@Roman\_Gonzalez](https://www.ruby-forum.com/u/Roman_Gonzalez)\
**Post date:** [July 28, 2007, 12:45am UTC](https://www.ruby-forum.com/t/activerecord-warnings-plugin-problem-when-extending-activer/110610/1 "2007-07-28T00:45:15Z")

</div>

Hi everyone.

I’m trying to make something cool with the ActiveRecord, it consists  
in adding the feature of warnings to it.  
for example:

class Person \< ActiveRecord::Base  
should\_warn\_presence\_of :name  
end

> > p = Person.new  
> > p.save  
> > =\> false
> 
> > p.warned?  
> > =\> true
> 
> > p.warnings.on(:name)  
> > =\> ‘should not be blank’
> 
> > p.accept\_warnings  
> > p.save  
> > =\> true

It makes the warning about an attribute, and the only way to save it  
is that you confirm that you accept the warnings.

When I’m trying to overwrite the validation functionality to handle  
the warnings and the validations of the model… the overwrite doesn’t  
work.

I imagine that this is happening because they use the  
“alias\_method\_chain :save, :validation” on the Validation module,

when I try to do this in a plugin to change the behavior of this  
method

module ActiveRecord  
module Validations  
def save\_with\_validation(perform\_validation = true)  
# code to handle the warnings  
end  
end  
end

it doesn’t get overwritten.

Maybe some dark magic is going on in the save\_with\_validation and the  
alias\_method\_chain.

Anyone has an idea?  
thanks in advance  
PD: if someone wants to see the code, pastie can help  
Roman.-

---

<div class="post-metadata">

**Author:** ![Roman\_Gonzalez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/50afbb/32.png) [@Roman\_Gonzalez](https://www.ruby-forum.com/u/Roman_Gonzalez)\
**Post date:** [July 28, 2007, 1:35am UTC](https://www.ruby-forum.com/t/activerecord-warnings-plugin-problem-when-extending-activer/110610/2 "2007-07-28T01:35:19Z")

</div>

When I execute the @person.save\_with\_validation, it works like a  
charm, but no when I invoke @person.save

probably there are to many alias\_method\_chain on the save method that  
maintains a reference to the old method of save\_with\_validation. Does  
that makes sense?
