为多个用户设计会话

时间:2013-07-05 02:36:36

标签: ruby-on-rails session devise

我正在使用两个非常独立的模型构建一个应用程序,它们都使用了auth。一旦您作为房屋登记,房屋中的每个人都可以作为该房屋的居民登录。除了当我使用

退出常驻会话时,一切正常
destroy_resident_session

唯一的问题是它也会因为调用

而杀死内部会话
Devise::SessionsController#destroy

我尝试为居民创建自定义会话,以下是我的代码:

class SessionsController < Devise::SessionsController

  # DELETE /resource/sign_out
  def destroy
    redirect_path = after_sign_out_path_for(resource_name)
    signed_out = sign_out(resident)
    set_flash_message :notice, :signed_out if signed_out && is_navigational_format?

    # We actually need to hardcode this as Rails default responder doesn't
    # support returning empty response on GET request
    respond_to do |format|
      format.all { head :no_content }
      format.any(*navigational_formats) { redirect_to redirect_path }
    end
  end
end

这会出错:

undefined local variable or method `resident'

我可能误解了方法逻辑,但似乎我想在设计会话控制器中更改以下行:

signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))

因为我不想退出所有范围,只有常驻范围。

解决

我所要做的就是设置

 config.sign_out_all_scopes = false

in

config/devise.rb

而且,还得记得重新启动我的服务器:)

1 个答案:

答案 0 :(得分:2)

这应该标记为答案。你没有发布它,但我有同样的问题,那就是解决方案,所以我发布它为社区

<强>配置/ devise.rb

 config.sign_out_all_scopes = false
相关问题