设计有“回调”? [英] Does devise have 'callback'?

查看:80
本文介绍了设计有“回调”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用户登录后,我想手动记录此事件并增加数据库中的计数器列。



有没有像$ code> after_login in Devise ?正如 ActiveRecord before_save

解决方案

Devise在幕后使用了Warden,Warden为您提供了许多回调:



https://github.com/hassox/warden/wiki/callbacks



看看 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)

这篇关于设计有“回调”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆