[英]Devise sessions for multiple users
我正在使用兩個都使用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'
我可能會誤解方法邏輯,但似乎我想在devise會話控制器中更改以下行:
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
由於我不想退出所有范圍,因此只能退出常駐范圍。
解決了
我要做的就是准備好
config.sign_out_all_scopes = false
在
config/devise.rb
而且,還必須記住重新啟動服務器:)
這應該被標記為答案。 您沒有發布它,但是我遇到了同樣的問題,這就是解決方案,所以我將其發布給社區
config / devise.rb
config.sign_out_all_scopes = false
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.