Forum: Ruby on Rails before_filter on Models

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sergio S. (Guest)
on 2009-03-22 21:29
(Received via mailing list)
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
Frederick C. (Guest)
on 2009-03-22 21:43
(Received via mailing list)
On Mar 22, 7:28 pm, Sergio S. <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
This topic is locked and can not be replied to.