Devise sign out not signing out

◇◆丶佛笑我妖孽 提交于 2019-12-25 03:01:31

问题


I'm having trouble signing out with devise. I am creating my signout link like this:

<%= link_to "Sign out", destroy_user_session_path %>

This was causing problems because the route could not be found so I added this to my routes.rb:

get 'sign_out', :to => 'users/sessions#destroy', :as => :destroy_user_session

Which does't cause any errors but also doesn't sign out, user_signed_in? still returns true.

Any ideas?


回答1:


try delete "logout" => "devise/sessions#destroy", :as => "logout" and

<%= link_to "Sign out", logout_path, :method => :delete %>




回答2:


It should be a DELETE request, which can be accomplished like this,

<%= link_to("Sign Out", destroy_user_session_path, :method => :delete) %>

This won't require you to add anything to your routes (assuming you have already added devise routes).




回答3:


Try this sign out link, it works for me

change your sign out link to

<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>  


来源:https://stackoverflow.com/questions/12240240/devise-sign-out-not-signing-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!