# Before\_filter on Models

**URL:** <https://www.ruby-forum.com/t/before-filter-on-models/163592>\
**Category:** Rails\
**Created:** [March 22, 2009, 8:29pm UTC](https://www.ruby-forum.com/t/before-filter-on-models/163592 "2009-03-22T20:29:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiburcio777](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@tiburcio777](https://www.ruby-forum.com/u/tiburcio777)\
**Post date:** [March 22, 2009, 8:29pm UTC](https://www.ruby-forum.com/t/before-filter-on-models/163592/1 "2009-03-22T20:29:20Z")

</div>

Hello everyone, is there a way to do something like after\_filter on  
models ?  
I would like to do something after one method in the model is executed,  
I  
don’t want to place that code in the model’s method, I would like to  
keep  
them in different methods, is there a way to do this ?

something like this:

after\_filter :do\_this, :only =\> do\_that

def do\_that  
…  
end

* * *

I don’t want to place the do\_this code inside do\_that, or call do\_this  
inside do\_that

def do\_that  
…  
do\_this if rtn == true  
end

Thanks in advice

---

<div class="post-metadata">

**Author:** ![tiburcio777](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@tiburcio777](https://www.ruby-forum.com/u/tiburcio777)\
**Post date:** [March 22, 2009, 8:43pm UTC](https://www.ruby-forum.com/t/before-filter-on-models/163592/2 "2009-03-22T20:43:59Z")

</div>

On Mar 22, 7:28 pm, Sergio S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello everyone, is there a way to do something like after\_filter on models ?  
> I would like to do something after one method in the model is executed, I  
> don’t want to place that code in the model’s method, I would like to keep  
> them in different methods, is there a way to do this ?

You might be interested in callbacks or observers. It wouldn’t be  
massively hard to write a small piece of magic so that

after\_filter :do\_this, :only =\> do\_that

replaced the do\_that method with one that called do\_that and do\_this  
if you really wanted to.

Fred
