Iván Vega Rivera
2005-Dec-01 22:06 UTC
Is it possible to do something before/after a method in a model and then do the default stuff?
Hi,
I don''t know if the subject makes sense, but what I want is to do
certain actions before a record is created, deleted, or updated, and
some other after a successful insert/delete/update.
like maybe:
class School < ActiveRecord::Base
def new
do something
call the default code that handles this function in Rails
if successful, do more stuff
end
end
I know I can do it in the controller, that''s pretty easy, but the tasks
I want to do involve updating some records on the database, so the code
should belong in the model, I think.
I''m sure this must be possible, but how?
Thanks in advance!
Ivan V.
Simon Santoro
2005-Dec-01 22:21 UTC
Re: Is it possible to do something before/after a method in a model and then do the default stuff?
Iván Vega Rivera wrote:> Hi, > > I don''t know if the subject makes sense, but what I want is to do > certain actions before a record is created, deleted, or updated, and > some other after a successful insert/delete/update.http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html