PrimeTimeTran PrimeTimeTran - 2 months ago 16
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'
end


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

config.sign_out_via = :delete
to
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
replacing
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'
end


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.

HELP PLEASE! t.T

You can look at the Github Repo here.

Answer

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