destroy_user_session_path is triggering GET instead of DELETE in Rails

后端 未结 3 1243
梦谈多话
梦谈多话 2021-01-23 15:55

I have the following code in my view:

  • <%= link_to \'Sign out\', destroy_user_session_path, method: :delete %>
  • Which

    相关标签:
    3条回答
    • 2021-01-23 16:47

      Consider these two points to get rid of this error:

      1. In your routes.rb (if you don't want to use :delete method):

        devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end

      2. sign_out link must have to contain :method => :delete (already you have)

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

        And finally, in your layout put:

        <%= javascript_include_tag :defaults %>

      Thanks.

      0 讨论(0)
    • 2021-01-23 16:48

      link_to fails back to a get if Javascript is not enabled. Looks like either your browser has Javascript disabled or more likely there is a Javascript error on the page. If there is an uncaught Javascript error on your page all other Javascript will fail to run after the error occurs.

      0 讨论(0)
    • 2021-01-23 16:51

      Do you have

      //= require jquery 
      //= require jquery_ujs
      

      in your application.js file?

      An alternative monkey patch would be to modify the devise.rb and change the signout method to get like so

      config/initializers/devise.rb

      config.sign_out_via = :get
      

      This post may shed some light: Rails 3.2 with Devise: logout link stopped working

      0 讨论(0)
    提交回复
    热议问题