destroy_user_session_path is triggering GET instead of DELETE in Rails

后端 未结 3 1244
梦谈多话
梦谈多话 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条回答
    •  慢半拍i
      慢半拍i (楼主)
      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.

    提交回复
    热议问题