No route matches /users/sign_out devise rails 3
I think the route for signing out is a DELETE
method. This means that your sign out link needs to look like this:
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
Yours doesn't include the :method => :delete
part. Also, please note that for this to work you must also include <%= javascript_include_tag :defaults %>
in your layout file (application.html.erb
).
Devise/Rails: No route matches [GET] /users/sign_out
Keep your devise.rb
using the correct HTTP method:
# good
config.sign_out_via = :delete
# bad
config.sign_out_via = :get
Use button_to
instead of link_to
# good
= button_to "Sign Out", destroy_user_session_path, method: :delete
# bad
= link_to "Sign Out", destroy_user_session_path, method: :delete"
If you are using bootstrap (keep it classy)
= link_to "Sign Out", destroy_user_session_path, method: :delete, class: "btn btn-default btn-sm"
Rails Devise Error No route matches [GET] /users/sign_out
Basically,
When you try to type url manually or you try to clickin link "sign-out" with new tab there are HTTP GET request and you will get No route matches [GET] "/users/sign_out"
, it doesn't exist because you have only via DELETE
request for /users/sign_out
on your routes.rb
, for the solution you can add this in config/initializer/devise.rb
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = Rails.env.test? ? :get : :delete
And change DELETE
to MATCH
request on your routes.rb
e.g : match 'users/sign_out' => "devise/sessions#destroy"
For reference : Devise for user management and authentication.
To be honest, supposed change the default 'delete' HTTP method it is not recommended. It's to user for test (e.g using cucumber)
Cucumber Testing for “Sign Out”
Jose Valim explained why: “GET requests should not change the state of
the server. When sign out is a GET request, CSRF can be used to sign
you out automatically and things that preload links can eventually
sign you out by mistake as well.”
@manoj mona's say 'we must not let the user to sign out by typing in the URL. It is a bad practice'
So, If user to sign out by type in the URL.
You can to define it, if get request it will redirect or render notice (like stackoverflow sign out)
Or don't use
link_to
tag for sign out, useinput
tag with form (like facebook sign out), so users can't type in the URL see this answer
Unable to sign out in a Rails app, using Devise gem, no route matches /users/sign_out
in devise.rb
find config.sign_out_via = :delete
change to config.sign_out_via = :get
if you use :get make sure you are using :method = :get and if you are using :delete using :method => :delete in your link
in production you may have to swap it round, so you should use an if statement to check RAILS_ENV
In your example you are probably running in development mode and not test, which is why it's probably not working.
And restart your server as it's an initialiser.
No route matches [GET] /users/sign_out rails 5
Try the following in routes.rb
devise_for :users
devise_scope :user do
get '/users/sign_out' => 'devise/sessions#destroy'
end
for more information how to by devise
No route matches [GET] /members/sign_out Devise
This happens when you do not have the gem jquery-ujs
installed or you are not calling the resulting javascript in your application via = javascript_include_tag "application"
, the response will be sent as a GET request, and the route will fail.
Check options below to make it work:
In
devise.rb
Changeconfig.sign_out_via
=:get
(not
recommended, since DELETE is the appropriate RESTful way to use this)config.sign_out_via = :delete
Use button instead of
link_to
to= button_to('Logout', destroy_user_session_path, :method => :delete)
With button_to Rails will do the heavy lifting on making the proper DELETE call. You can
then style the button to look like a link if you wish.In your routes.rb
devise_for :members do
get '/members /sign_out' => 'devise/sessions#destroy'
end
Rails Devise Gem Sign_Out Fails to sign out
undefined method `sign_out_via_get_because_of=' for Devise:Module
(NoMethodError)
There is no sign_out_via_get_because_of
helper for devise. There is only sign_out_via
uninitialized constant UsersController
You don't have users_controller.rb
under app/controllers
, so is the error.
#app/controllers/users_controller.rb
class UsersController < ApplicationController
end
For "sign_out_via" what exactly should I type?
It depends on the method
parameter in your link_to
. If it is :method => :delete
then config.sign_out_via = :delete
else config.sign_out_via = :get
.
By convention should I run Rails g controller User or Rails g
controller Users?
You should run rails g controller Users
No route matches /users/sign_out devise rails 3
I think the route for signing out is a DELETE
method. This means that your sign out link needs to look like this:
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
Yours doesn't include the :method => :delete
part. Also, please note that for this to work you must also include <%= javascript_include_tag :defaults %>
in your layout file (application.html.erb
).
unable to use sign_out in ruby on rails devise gem
Hope this could help
Try this in your routes.rb
devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end
Related Topics
How to Overwrite the '{ }' Object
Assets Precompiling Error with Jquery UI Plugin
How to Create Activerecord Style Validations Outside of Activerecord
Does Will Pagination Work with Forms Which Have Method="Post"
Multiple Limit Condition in Mongodb
Duplicates in 2 Dimensional Array
Jekyll Custom Theme- Gemspec Bundle Install Error: Unexpected Unary-, Expecting Keyword_Do
Create Multiple Records with Fields_For - Rails
What Is the Path to Learn Bdd on Ruby on Rails
Programming a Simple Irc (Internet-Relay-Chat) Client
Ruby on Rails CSV Upload&Import - File Name Too Long
Can't Run a Ruby Hello World Application in Aptana
Ruby: Sorting 2 Arrays Using Values from One of Them
How to Link to a Nested Route Path Inside a Loop
Reply to Thread Google-Api-Ruby-Client