【发布时间】:2013-07-05 02:36:35
【问题描述】:
我正在构建一个应用程序,其中包含两个非常独立的模型,两者都使用 devise for 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
在
config/devise.rb
而且,必须记住重新启动我的服务器:)
【问题讨论】:
-
你摇滚!正在努力解决同样的问题。这个选项确实应该在 README 的“配置多个模型”中提及。 :) BTW-你应该正式回答这个问题,然后接受你自己的答案。
-
我支持它:你应该添加你的解决方案作为这个问题的答案,然后接受这个答案作为正确的答案。
标签: ruby-on-rails session devise