加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何设计销毁会话并从控制器注销?

发布时间:2020-12-17 04:35:16 所属栏目:百科 来源:网络整理
导读:设计销毁会话并从控制器退出? if something_is_not_kosher # 1. log this event,2. send notice redirect_to destroy_user_session_path and returnend 还尝试过: if something_is_not_kosher # 1. log this event,2. send notice redirect_to 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中删除.也许设计有一个方法? current_user.sign_out并试过sign_out(current_user)哪个也行不通?谢谢您的帮助.

耙路线:

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

解决方法

你为什么不使用devise的内置 sign_out_and_redirect(current_user)方法?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读