简体   繁体   English

使用Devise登录后如何设置会话变量?

[英]How to set a session variable after sign in with Devise?

I'm trying to find out where to set a session variable once a user has logged in using Devise. 我试图找出用户使用Devise登录后在哪里设置会话变量。 I found this post (and others): 我发现了这篇文章(和其他内容):

Set a session variable in devise on sign in 在登录时设计一个会话变量

So I tried something like this: 所以我尝试了这样的事情:

protected
    # when a user logs in
    def after_sign_in_path_for(resource_or_scope)
      session[:current_account_id] = current_user.accounts.find_by_is_default(true).id # get id of row where it's is_default is set as true
      abort(session[:current_account_id])
    end

..but no joy. ..但没有喜悦。 I don't want to do an alternative redirect (as the issue in the link was asking), just set a session variable when the user logs in, so I'm not sure if this is the callback I'm wanting. 我不想执行其他重定向(因为链接中的问题正在询问),只需在用户登录时设置一个会话变量,所以我不确定这是否是我想要的回调。 Also, I may have my find_by_ method wrong but I was hoping I could debug (using abort) once the script gets that far - but it doesn't appear to be as abort doesn't seem to be called. 另外,我可能有我的find_by_方法错误,但是我希望一旦脚本达到那么远就可以调试(使用中止)-但这似乎不是,因为似乎没有调用中止。 Any help much appreciated. 任何帮助,不胜感激。 Thanks 谢谢

确保受保护的方法位于ApplicationController内部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM