Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有人可以向我解释Ruby on Rails 4 中的回调:before_save和Active Record 回调之间的区别吗?:before_update
:before_save
:before_update
我通读了有关 Active Record 回调的官方文档,但找不到足够详细的解释。
:before_save每次在数据库中插入/更新记录时都会调用。因此,无论是新记录还是现有记录,每次保存都会调用它。
:before_update仅在记录更新时调用,并且从不在新记录中调用。