简体   繁体   中英

Rails & Devise: destroy_user_session_path going to Users#Show?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM