问题
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