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

设计销毁会话并从控制器退出
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)方法

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...