0
votes

I am using devise for authentication and for now, I can sign-up a user who is automatically logged in.

However, devise does not recognise the path localhost:3000/users/sign_out

It gives an error

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

In my routes, I have the devise_for :users statement as I generated devise for Users.

I have devise set up well in my users model too, user.rb as follows

class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
end

My rake routes show the following

destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy

Anyone know why my URL path is not being recognised

1

1 Answers

0
votes

It is because the route expects a DELETE HTTP action not a GET action.

destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy

By Entering a URL in the browser you are sending a GET action to that URL.

In order to make devise accept GET action for the sign_out route change in devise.rb:

config.sign_out_via = :delete

to 

config.sign_out_via = :get

An alternative is to add a :method => :delete to the link in the view, this way a DELETE action will be sent to your server as Devise expects.