我希望在登录后/ session 创建后 Hook 到设计。我该怎么做呢?
基本上我想在用户每次登录时设置一个用户位置,为此我需要一个登录后 Hook 。
最佳答案
Devise 建立在 Warden 之上,因此您可以使用 Warden 的 after_authentication Hook 。
把它放在一个初始化器中:
Warden::Manager.after_authentication do |user,auth,opts|
# do something with user
end
远程 IP 地址和其他请求信息存储在 auth.request(即 auth.request.remote_ip)中。
见 https://github.com/hassox/warden/wiki/callbacks
关于ruby-on-rails - rails 设计 Hook 到 on_login,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7970728/