How can I intercept AR creates/updates to automatically set fields in the table?

I would like to add functionality like the update_on/created_on etc fields and intercept updates and creates so that I can drop in data into certain fields at the last minute.

I am not sure what the best Railer approach would be. Observers? Override some AR methods from within my model? Any guidance on this would be appreciated, thanks.

Chad

Hey Chad, you can use Rail's callbacks to handle this for you. Thus,
if you need to do some post processing of create and update actions,
then one can do the following within your model classes:

def after_create
  # do some stuff
end

def after_update
  # do some stuff
end

For more information, please section 19.2 of AWDwRv2

Good luck,

-Conrad

Thanks Conrad, it was staring me in the face all this time.

if you want to catch something before your models are saved, vs.
after, which is what it sounds like, use before_save callback. it
will be called before a create or update.