What is the difference between the :before_save an

2020-06-01 08:36发布

问题:

Could someone please explain to me the difference between the :before_save and :before_update Active Record callbacks in Ruby on Rails 4?

I read through the official documentation on Active Record callbacks, but I couldn't find a granular-enough explanation.

回答1:

:before_save is called everytime a record is inserted/updated in the database. So it is called on every save whether its a new record or existing record.

:before_update is called only when the record is updated & never on new record.