在devise中设置会话变量登录 [英] Set a session variable in devise on sign in
问题描述
一旦用户根据用户表中的某个字段登录,我想设置一个会话变量。如果我不需要,我不想要创建一个自定义的Devise控制器。有办法吗还是我必须去定制控制器路由?
有一个回调 after_sign_in_path_for ,您可以将其添加到 ApplicationController
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ = current_user.domain_prefix
user_path(resource)
end
不要忘记路径在方法的最后一行,否则回调将重定向请求到 session [:domain_prefix]
的内容
I'd like to set a session variable once a user signs in based on a certain field in the User table. I don't want to have to create a custom Devise controller if I don't have to. Is there a way? Or will I have to go the custom controller route?
There is a callback after_sign_in_path_for, you can add it in your ApplicationController
protected
def after_sign_in_path_for(resource)
session[:domain_prefix] = current_user.domain_prefix
user_path(resource)
end
Dont forget return the path in the last line of method, otherwise the callback will redirect the request to content of session[:domain_prefix]
这篇关于在devise中设置会话变量登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!