No route matches [GET] “/users/sign_out”

萝らか妹 提交于 2019-11-27 18:11:05
cramhead

I had a similar problem, but addition of the :method=> :delete didn't work. I was able to add a new route for a the get request by commenting out the devise_for :users and adding

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

You can end a session via get by changing the devise configuration in initializers.

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

Just open the link and your session is removed.

Although I don't know the cause, the reason why you are getting that message is because in your routes you have

destroy_member_session DELETE /members/sign_out(.:format)      {:action=>"destroy", :controller=>"devise/sessions"}

Which means that route is only available with the DELETE method as opposed to GET. This is a bit weird since in the docs for devise it says that it should create it as GET route (https://github.com/plataformatec/devise/blob/master/lib/devise/rails/routes.rb#L30)

With it as a DELETE route, you should be able to logout using

link_to :logout, destroy_member_session_path, :method => :delete 
Victor Martins

I just needed to add the

//= require jquery
//= require jquery_ujs

to my application.js

I had a similar problem. My view code was like this:

  <%= link_to " exit", destroy_user_session_path, method: :delete %>

After adding the following change to routes.rb it worked,

devise_for :users

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

We still can use :method => :delete in my code, like that

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

The reason i think we fail to load javascript that include jquery, make sure

= javascript_include_tag "application" (haml- you can use html too)

to include jquery-ui and jquery-ujs. So if it still error, i suggest to change rails gem in GEMFILE to version 3.2.6 and call bundle update to update gems. It works for me!

Nikhil Nanjappa
= link_to "Sign out", destroy_user_session_path,:method => :delete

will NOT work instead use this,

= link_to "Sign out", destroy_user_session_path,:method => 'delete'

should do the trick or worse case add require jquery_ujs in your application.js

loloso

In devise.rb, change

 config.sign_out_via = :delete

to

config.sign_out_via = :get

This worked for me. I went crazy with this because the default is delete and I don’t understand why.

This works, but I am not sure whether it affects other elements in the application.

Using Rails4, I had to use the following method:

<%= link_to "Logout", destroy_admin_session_path, method: :delete %>

Emphasis on where the colons are on method: and :delete

Maybe that will help somebody. Upgraded from Rails 3.0 to 3.1 and found this problem. This fixed it for me:

routes.rb:
devise_for: users

devise.rb:
config.sign_out_via = :delete

application.html.erb:

<%= javascript_include_tag "application" %>     

* not :defaults

_login_items.html.erb:

<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>

app/assets/javascripts/application.js

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require_tree .

and I had in javascript/ jquery.js, jquery_ujs.js from 3.0 version that I've removed.

You may have removed assets/javascripts/*

Run rails generate jquery:install --ui this will generate all the javascripts as shown below

xxxx@xxxxx:~/Projects/Rails_apps/rtest$ rails generate jquery:install --ui
      remove  public/javascripts/prototype.js
      remove  public/javascripts/effects.js
      remove  public/javascripts/dragdrop.js
      remove  public/javascripts/controls.js
     copying  jQuery (1.7.1)
      create  public/javascripts/jquery.js
      create  public/javascripts/jquery.min.js
     copying  jQuery UI (1.8.16)
      create  public/javascripts/jquery-ui.js
      create  public/javascripts/jquery-ui.min.js
     copying  jQuery UJS adapter (822920)
      remove  public/javascripts/rails.js
      create  public/javascripts/jquery_ujs.js

Go to your layout e.g application.html.erb and edit <%= javascript_include_tag :all %>

That worked for me :)

FWIW I have also run into this problem. Have looked into all of the suggested answers however the only one which worked was to foto open routes.rb and comment out the following line:

devise_for :users

Below that, add the following line:

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

The problem begins with rails 3.1 in assets/javascript/. Just look for application.js, and if the file doesn't exist, create a file with that name. I don't know why my file disappears or never was created on rails new app... that file is the instance for jquery.

@creamhost say,

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

but it is not correct solution for me (Rails4). I solved our problem (@Olives' answer),

link_to :logout, destroy_member_session_path, method: :delete

Just use the following for your sign out link:

<%= link_to "Sign out", destroy_user_session_path, method: :delete %>
Idrees Ibrahim
//= require jquery_ujs

You are missing this line in your assets. There's no need to get /users/signout request. Put this line into JavaScript file at very top of the page.

Had the same problem and remembered it only started happening after I decided to "clean up" my Javascript files. So I ran rails generate jquery:install --ui again and this solved it for me. (You can ignore the --ui part if you don't need JQuery UI, I suppose.)

I was getting the same error the OP had for /users/sign_out because I was GETTING it instead of DELETING it (I too am a 1st year dev). After checking github via this answer, I submitted the pull request to correct it!

https://github.com/plataformatec/devise/pull/2040

Go S.O. !!!

It happens only on windows.. Add the following thing to your Application.html.erb file.

devise_for :users

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!