Rails 3使用devise重置会话 [英] Rails 3 reset session using devise

查看:135
本文介绍了Rails 3使用devise重置会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Devise进行认证开发Rails3应用程序。在工作流程中,像session_id这样的数据存储在会话中。但是,当用户登录时,会话需要清除。由于Devise处理用户登录/注销,我无法控制,因此无法确定如何重置会话数据。



如何处理这种情况?

解决方案

覆盖Devise :: SessionsController like this:

  class SessionsController< Devise :: SessionsController 
respond_to:html
def destroy
super
reset_session
end
end

不要忘记将设计视图移动到正确的位置(views / devise / sessions查看/会话),并修改设计路线以指向控制器。例如:

  devise_for:users,:controllers => {:sessions => 会话} 

请参阅github上的devise文档以获取更多详细信息或Bill发布的链接。 / p>

I am developing a Rails3 application using Devise for authentication. In the course of the workflow, data like patient_id is stored in the session. However, when the user log's out, the session needs to be cleared. I am unable to figure out how to reset session data since Devise handles users login / logout and I not having control over it.

How to handle this situation?

解决方案

Overwrite Devise::SessionsController like this:

class SessionsController < Devise::SessionsController
  respond_to :html
  def destroy
    super
    reset_session
  end
end

Don't forget to move the devise views to the right place (views/devise/sessions to views/sessions) and modify the devise route to point to your controller. For example:

devise_for :users, :controllers => { :sessions => "sessions" }

See the devise docs on github for more details or the link posted by Bill.

这篇关于Rails 3使用devise重置会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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