问题描述
在用户登录后,我想手动记录此事件并增加数据库中的计数器列。
有没有像$ code> after_login in Devise
?正如 ActiveRecord
的 before_save
?
Devise在幕后使用了Warden,Warden为您提供了许多回调:
看看 after_authentication
回调。这是你正在寻找的。
代码:
:Manager.after_authentication do | user,auth,opts |
#你的代码在这里..
end
你可以简单地创建一个新的初始化程序文件并将代码放在那里。 (像 /config/initializers/warden_callbacks.rb
)
After a user log in, I want to manually log this event and increment a counter column in database.
Is there something like after_login
in Devise
? Just as ActiveRecord
's before_save
?
Devise uses Warden behind the scenes and Warden supplies you with a number of callbacks:
https://github.com/hassox/warden/wiki/callbacks
Have a look at the after_authentication
callback. That's what you are looking for.
Code:
Warden::Manager.after_authentication do |user, auth, opts|
# your code here..
end
You can simply create a new initializer file and put the code there. (Like /config/initializers/warden_callbacks.rb
)
这篇关于设计有“回调”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!