What is the difference between the :before_save an

2020-06-01 09:06发布

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条回答
走好不送
2楼-- · 2020-06-01 09:26

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

查看更多
登录 后发表回答