Is it possible to do something before/after a method in a mo


#1

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.


#2

Iván Vega R. 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