PrimeTimeTran PrimeTimeTran - 21 days ago 4
Ruby Question

Rails Devise Gem "Sign_Out" Fails to sign out

Error Message

Rails Server
Processing by Devise::SessionsController#destroy as HTML
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
Can't verify CSRF token authenticity
(0.4ms) BEGIN
(0.1ms) COMMIT

I read this article thoroughly, my question is not a repeat because I researched!

I tried Cramheads suggestion:
Added this to routes.rb

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

I tried itkevins suggestion: changed devise.rb's default from

config.sign_out_via = :delete
config.sign_out_via = :get

this resulted in a routing error:

uninitialized constant UsersController

I tried Rickys suggestion: changed devise.rb

config.sign_out_via_get_becuase_of = :ie

this resulted in a method error:

undefined method `sign_out_via_get_because_of=' for Devise:Module (NoMethodError)

I tried Olives suggestion: adjusted the code slightly

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

I tried Victor Martins suggestion: Already had this in application.js

//= require jquery
//= require jquery_ujs

I tried Rezas suggestion: In routes.rb

devise_for :users

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

I followed DuyKhoas suggestion as well:
I included javascript

<%= javascript_include_tag(:application) %>

I already had this so this wasn’t helpful either.

All the other suggestions were repeats of the already suggested fixes.


You can look at the Github Repo here.


undefined method `sign_out_via_get_because_of=' for Devise:Module

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.


class UsersController < ApplicationController

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