本文介绍了在sign_in后访问新的session_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用设计 &覆盖 SessionsController#create 以根据特定条件跟踪登录.

I am using devise & overriding SessionsController#create to track the login based on a specific condition.

sign_in(user) 前 session[:session_id] 的值即使在 sign_in(user) 执行后也是一样的.

The value of session[:session_id] before sign_in(user) is same even after the execution of sign_in(user).

我想将新的 session_id 存储在数据库中以跟踪用户.但无法访问它.如何获得?

I would like to store the new session_id in DB in order to track the user. But unable to access it. How to get it?

在找的时候,发现Devise使用了Warden的set_user方法.但即便如此,我也无法弄清楚在 Warden 中的会话设置在哪里.

While looking for it, found that Devise uses set_user method of Warden. But even then, I could not figure out where the session is set in Warden.

推荐答案

在以下问题中找到答案:

Found the answer in the following question:

Rails ActiveRecord 存储和新会话

本杰明辛克莱尔的回答对我有用(虽然它没有被标记为答案).刚刚用 request.session_options 替换了 session.options

Answer by Benjamin Sinclaire worked for me (though it was not marked as answer). Just replaced session.options with request.session_options

这篇关于在sign_in后访问新的session_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 21:43