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

1

22

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.

Bobbybobbye answered 27/8, 2013 at 16:18 Comment(0)
F
42

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

Frontier answered 27/8, 2013 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.