No route matches [GET] “/users/sign_out”

前端 未结 19 1485
谎友^
谎友^ 2020-12-04 18:44

Here is my actual error: No route matches [GET] \"/members/sign_out\" Since most people will use \"users\" I thought it would be more helpful to have that in th

相关标签:
19条回答
  • 2020-12-04 19:05

    You can end a session via get by changing the devise configuration in initializers.

    # The default HTTP method used to sign out a resource. Default is :delete.
    config.sign_out_via = :get
    

    Just open the link and your session is removed.

    0 讨论(0)
  • 2020-12-04 19:05

    Using Rails4, I had to use the following method:

    <%= link_to "Logout", destroy_admin_session_path, method: :delete %>
    

    Emphasis on where the colons are on method: and :delete

    0 讨论(0)
  • 2020-12-04 19:05
    //= require jquery_ujs
    

    You are missing this line in your assets. There's no need to get /users/signout request. Put this line into JavaScript file at very top of the page.

    0 讨论(0)
  • 2020-12-04 19:07

    I had a similar problem. My view code was like this:

      <%= link_to " exit", destroy_user_session_path, method: :delete %>
    

    After adding the following change to routes.rb it worked,

    devise_for :users
    
    devise_scope :user do  
       get '/users/sign_out' => 'devise/sessions#destroy'     
    end
    
    0 讨论(0)
  • 2020-12-04 19:07

    Just use the following for your sign out link:

    <%= link_to "Sign out", destroy_user_session_path, method: :delete %>
    
    0 讨论(0)
  • 2020-12-04 19:12

    Although I don't know the cause, the reason why you are getting that message is because in your routes you have

    destroy_member_session DELETE /members/sign_out(.:format)      {:action=>"destroy", :controller=>"devise/sessions"}
    

    Which means that route is only available with the DELETE method as opposed to GET. This is a bit weird since in the docs for devise it says that it should create it as GET route (https://github.com/plataformatec/devise/blob/master/lib/devise/rails/routes.rb#L30)

    With it as a DELETE route, you should be able to logout using

    link_to :logout, destroy_member_session_path, :method => :delete 
    
    0 讨论(0)
提交回复
热议问题