在 Rails 5.1 中对用户 create/update/delete/login/logout 进行 运行 编码的最佳方法是什么?

What is the best way to run code on user create/update/delete/login/logout in Rails 5.1?

每当 Rails 5.1 应用程序中发生以下事件时,发出 HTTP POST 请求的正确方法是什么?

根据上面的评论,我选择了 this solution:

During the normal operation of a Rails application, objects may be created, updated, and destroyed. Active Record provides hooks into this object life cycle so that you can control your application and its data.

Callbacks allow you to trigger logic before or after an alteration of an object's state.