Reputation: 5073
Pretty standard link:
<li><%= link_to 'Log Out', destroy_user_session_path(current_user) %></li>
rake routes:
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
routes.rb:
devise_for :users, :controllers => { omniauth_callbacks: "users/omniauth_callbacks", sessions: "users/sessions" }
users/sessions_controller.rb:
class Users::SessionsController < Devise::SessionsController
def destroy
binding.pry
cookies.delete(:auth_token)
flash[:notice] = "Successfully Logged Out"
redirect_to new_session_path
end
end
binding.pry is not even being called. The link takes me to the url /users/sign_out
but the view is Users#show.
Any ideas?
Upvotes: 0
Views: 415
Reputation: 327
The destroy action requires the DELETE HTTP verb as shown in your rake routes
output.
You need to add method: :delete
to the end of your link helper, otherwise the link will produce a GET request.
Upvotes: 1