如何设计销毁会话并从控制器注销? [英] How to devise destroy session and sign out from controller?
本文介绍了如何设计销毁会话并从控制器注销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Devise销毁会话并从控制器注销?
Devise destroy session and sign out from controller?
if something_is_not_kosher
# 1. log this event, 2. send notice
redirect_to destroy_user_session_path and return
end
也尝试过:
if something_is_not_kosher
# 1. log this event, 2. send notice
redirect_to controller: 'devise/sessions', action: 'destroy', method: :delete and return
end
错误为没有路由匹配[GET] / users / sign_out
,但是我在示例2中明确设置了方法::delete。也许设计了一个方法? current_user.sign_out
并尝试了sign_out(current_user)还是不起作用?
Error is No route matches [GET] "/users/sign_out"
but I'm explicitly setting method: :delete in example 2. Maybe devise has a method? current_user.sign_out
and tried sign_out(current_user) which also don't work? Thanks for the help.
耙道:
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
user_registration POST /users(.:format) users/registrations#create
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
推荐答案
所以我最终通过创建自定义登出路线来解决了这个问题
So I ended up solving this by creating a custom signout route
devise_scope :user do
get '/signout', to: 'devise/sessions#destroy', as: :signout
end
,在我的控制器中,我有:
and in my controller I have:
if something_is_not_kosher
redirect_to signout_path and return
end
这篇关于如何设计销毁会话并从控制器注销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文