Callback methods

after_create()

This will be called after saving the object (for eg.., @sample.save). At this time no record exists.

after_destroy()

This will be called after destroying the object (for eg.., @sample.destroy)

after_save()

This will be called after saving the object (for eg.., @sample.save),  regardless of create (or) update

after_update()

This will be called after saving the object (for eg.., @sample. save), on the existing objects that have the record.

after_validation()

This will be called after the validation has been done (regardless of create or update)

after_validation_on_create()

This will be called after the validation on new object that has not yet been saved.

after_validation_on_update()

This will be called after the validation on the existing objects that has the record.

On the same way we can use the following methods respectively, for calling the method before doing some operations.

  1. before_create()
  2. before_destroy()
  3. before_save()
  4. before_update()
  5. before_validation()
  6. before_validation_on_create()
  7. before_validation_on_update()
Advertisements