Devise / Rails: no route match [GET] "/ users / sign_out"

I am a little confused about how devise routes my requests, for some reason I cannot go to the exit path in my application now:

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

Here is what my routes related to my user model and Devise look like:

 devise_for :users, :controllers => {:registrations => "registrations"} devise_scope :user do get '/settings' => 'registrations#edit' end 

Will defining this area interfere with my other routes?

Refresh

I don’t think it should be a GET request, as my link looks like this:

 <%= link_to "Sign out", destroy_user_session_path, :method => :delete %> 
+6
source share
5 answers

If you try to go to / users / sign _out by typing it in the address bar of your browser or usually referring to it, you will get this error. To summarize some of the comments and answers here and from problems when creating a repo on github:

This is an assigned functionality; RESTful applications should not change state with a GET request.

You can fix this by installing a link that uses the DELETE method, as indicated by @Trip, @fuzzyalej, and an update by @Joseph Silvashy.

Alternatively (and less recommended) in /config/initializers/devise.rb you can make the following change

 config.sign_out_via = :delete 

to

 config.sign_out_via = :get 

I ran into this problem, following along with http://railscasts.com/episodes/209-introducing-devise and with the older version that he used there, this is not a problem.

+14
source

The only way this post has the answer:

This must be sent using the delete method so that it is not the default get

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

If you use SSL using Devise controllers and try to exit the http URL, what happens is that it sends a DELETE request to the #destroy method, but then redirects to the https version via GET. You can fix this by adding https to the exit link:

 = link_to "Sign out", destroy_user_session_url(protocol: 'https'), method: :delete 

Note: must be "url" instead of "path"

+3
source

From the rails of the documentation :

 link_to("Destroy", "http://www.example.com", :method => :delete, :confirm => "Are you sure?") # => <a href='http://www.example.com' rel="nofollow" data-method="delete" data-confirm="Are you sure?">Destroy</a> 
0
source

I had the same problem, and the following steps were taken to solve it: 1) include // = require jquery_ujs in assets /javascripts/application.js 2) add gem 'jquery-rails' to my gemfile 3) install the package

... and he worked.

0
source

Source: https://habr.com/ru/post/910109/


All Articles