One minute
Validations & Callbacks on different events in Rails ⚓️

Validations
They are used to ensure that only valid data is saved into your database. i.e. check user email presence, check email uniqueness etc.
Callbacks
They are methods that get called at certain moments of an object’s life cycle. With callbacks it is possible to write code that will run whenever an object is created, saved, updated, deleted, validated, or loaded from the database.
The following table gives idea about whether validation and callbacks are called or not on ruby object method:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
method | validation | callbacks | |
---|---|---|---|
save | ✔ | ✔ | |
save(validate: false) | ✘ | ✔ | |
update | ✔ | ✔ | |
update_attribute | ✘ | ✔ | |
update_attributes | ✔ | ✔ | |
update_all | ✘ | ✘ | |
set(for mongoid only) | ✘ | ✘ |
Read other posts