devise icon indicating copy to clipboard operation
devise copied to clipboard

No route matches [GET] "/users/sign_out"

Open kinsbrunner opened this issue 9 years ago • 18 comments

Hi guys,

I have been struggling for hours with this error which happens when having a link_to for destroying the session. For some reason, a GET is being sent instead of a DELETE action which makes this error happen.

Some points to highlight:

  • Rails version 5.0.2, Devise 4.2.1, jquery-rails 4.3.1
  • Yes, I have included the method: :delete (<%= link_to 'Exit', destroy_user_session_path, method: :delete %>)
  • Yes, Routes file is set correctly (destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy)
  • Yes, on my application.html.erb I have already included the following lines:
    <%= csrf_meta_tags %>
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
  • My application.js file looks as the following:
//= require jquery2
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require dataTables/extras/dataTables.responsive
//= require turbolinks
//= require tether
//= require bootstrap-sprockets
//= require_tree .
  • No, I am not willing to switch the Devise initializer to sign out via :get instead of :delete, I believe that's not "nice".
  • If switching from link_to into button_to, it perfectlly works which makes me understand this issue is related to JS/jQuery topics.
  • Everything was working fine until I added a theme

Not sure whether this could be related to the version of a gem (already played using previous versions of jQuery, Devise, etc)

Kindly let me know your ideas. Thanks and regards. Alejandro.

kinsbrunner avatar Apr 04 '17 00:04 kinsbrunner

Let me add something weird which I am seeing through Console:

Started DELETE "/users/sign_out" for 10.0.2.2 at 2017-04-04 00:59:51 +0000
Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Devise::SessionsController#destroy as HTML
  Parameters: {"authenticity_token"=>"bImblK3CLXPXMpBaJNm1opywnGWm+DABf2rBRjAuzC5dJJenf8aPgEHln/pT6dQCqexTOIbrMKgYpCVyel8D8w=="}
  User Load (0.8ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
Redirected to http://localhost:3030/
Completed 302 Found in 7ms (ActiveRecord: 0.8ms)

Started GET "/" for 10.0.2.2 at 2017-04-04 00:59:51 +0000
Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by DashboardsController#index as HTML
  Rendering dashboards/index.html.erb within layouts/application
  Rendered dashboards/index.html.erb within layouts/application (0.5ms)
Started GET "/users/signo_out" for 10.0.2.2 at 2017-04-04 00:59:52 +0000
Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255

ActionController::RoutingError (No route matches [GET] "/logout"):

What it sounds weird to me is that it first triggers the DELETE to the correct "place", then a GET to "/" and, finally, the GET to "users/signo_out" which generates the error.

kinsbrunner avatar Apr 04 '17 01:04 kinsbrunner

Guys, Just tried removing all the theme JS and started adding them back until I found the piece of js which was changing controls. This is definitely not a gem related bug so I am closing the issue. Regards. Alejandro.

In my case the problem occurred because I'm not using jquery on the project

laurenmacam avatar Aug 18 '17 14:08 laurenmacam

Still facing the same problem (and I am not even using js)

mittalyashu avatar Sep 09 '17 15:09 mittalyashu

hey, @kinsbrunner , did you manage to solve this problem? I have the same issue and I'm can't figure out what's the problem

Nechitadi avatar Jan 19 '18 07:01 Nechitadi

I solved this issue using jquery-ujs. If you look into the readme it says:

make non-GET requests from hyperlinks

jorgearimitsu avatar Aug 07 '18 02:08 jorgearimitsu

Is there any way to get this working without having to use jQuery?

julianguyen avatar Dec 02 '18 21:12 julianguyen

By default the sign out route uses the DELETE HTTP method. You can either make an ajax yourself - without the help of jQuery - or change the Devise configuration to accept sign out as a GET request.

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

tegon avatar Dec 03 '18 11:12 tegon

Is there any way to get this working without having to use jQuery?

You can use the button_to helper and style the button if you need.

<%= button_to 'Exit', destroy_user_session_path, method: :delete %>

jorgearimitsu avatar Dec 05 '18 15:12 jorgearimitsu

Is there any way to get this working without having to use jQuery?

You can use the button_to helper and style the button if you need.

<%= button_to 'Exit', destroy_user_session_path, method: :delete %>

hi Jorge, it's worked Thanks

fahrulrizall avatar Oct 31 '19 13:10 fahrulrizall

Having the same problem here. My app is not using any JS and config.sign_out_via = :get doesn't make any difference.

@kinsbrunner shouldn't this issue be reopened?

ghost avatar Jan 13 '20 15:01 ghost

Can you reopen this issue?

binyamindavid avatar May 01 '20 05:05 binyamindavid

Can you provide a sample application that reproduces the issue? If we can confirm it's reproducible in a sample app, we can reopen and investigate further. Thanks.

carlosantoniodasilva avatar May 01 '20 11:05 carlosantoniodasilva

I found that issue. In rails 6, I had include jquery and popper.js

const { environment } = require('@rails/webpacker')

const webpack = require('webpack')
environment.plugins.append(
  'Provide',
  new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery',
    Popper: ['popper.js', 'default']
  })
)


module.exports = environment

This fixed the problem.

binyamindavid avatar May 01 '20 11:05 binyamindavid

Tegon;s solution worked for me

Devise.setup do |config|

The default HTTP method used to sign out a resource. Default is :delete.

config.sign_out_via = :get end

ghost avatar May 29 '20 14:05 ghost

Is there any way to get this working without having to use jQuery?

I fixed this by installing the gem "rails-ujs" and going into app/assets/javascripts/application.js and adding this code: //= require rails-ujs

Hope this helps anyone dealing with this error

jose-Abel avatar Nov 01 '20 20:11 jose-Abel

Dont know if someone still has this issue but i did a combination of 2 solutions:

i changed HTTP default :delete to :get (by @tegon )

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

and i used the rails-ujs gem as well as a safety net since i was in a time crunch to deploy (by @jose-Abel )

aadikrs avatar Nov 30 '21 13:11 aadikrs

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

Thank you so much, you saved my day ...

shiccorama avatar Mar 12 '23 21:03 shiccorama