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

前端之家收集整理的这篇文章主要介绍了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)方法
原文链接:https://www.f2er.com/ruby/269418.html

猜你在找的Ruby相关文章