Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kinsbrunner opened this issue Apr 4, 2017 · 18 comments
Closed

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

kinsbrunner opened this issue Apr 4, 2017 · 18 comments

Comments

@kinsbrunner
Copy link

kinsbrunner commented Apr 4, 2017

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
Copy link
Author

kinsbrunner commented Apr 4, 2017

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
Copy link
Author

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.

@laurenmacam
Copy link

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

@mittalyashu
Copy link

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

@Nechitadi
Copy link

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

@jorgearimitsu
Copy link

jorgearimitsu commented Aug 7, 2018

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

make non-GET requests from hyperlinks

@julianguyen
Copy link

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

@tegon
Copy link
Member

tegon commented Dec 3, 2018

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

@jorgearimitsu
Copy link

jorgearimitsu commented Dec 5, 2018

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 %>

@fahrulrizall
Copy link

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

@ghost
Copy link

ghost commented Jan 13, 2020

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?

@binyamindavid
Copy link

Can you reopen this issue?

@carlosantoniodasilva
Copy link
Member

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.

@binyamindavid
Copy link

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.

@PrincetonAfeez
Copy link

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

@jose-Abel
Copy link

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

@aadikrs
Copy link

aadikrs commented Nov 30, 2021

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 )

@shiccorama
Copy link

<%= 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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests