Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the :before_save and :before_update Active Record callbacks?

Tags:

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.

like image 934
Vilmos Csizmadia Avatar asked Aug 27 '13 16:08

Vilmos Csizmadia


1 Answers

: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.

like image 173
techvineet Avatar answered Sep 20 '22 02:09

techvineet