在登录时在设计中设置会话变量 [英] Set a session variable in devise on sign in

查看:17
本文介绍了在登录时在设计中设置会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户登录后根据用户表中的某个字段设置一个会话变量.如果不需要,我不想创建自定义设计控制器.有办法吗?还是我必须走自定义控制器路线?

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?

推荐答案

有回调 after_sign_in_path_for,您可以将其添加到您的 ApplicationController

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

不要忘记在方法的最后一行返回路径,否则回调会将请求重定向到session[:domain_prefix]

Dont forget return the path in the last line of method, otherwise the callback will redirect the request to content of session[:domain_prefix]

这篇关于在登录时在设计中设置会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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