0

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.

Community
  • 1
  • 1
PrimeTimeTran
  • 1,081
  • 1
  • 10
  • 25

1 Answers1

0

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

Pavan
  • 32,201
  • 7
  • 42
  • 69
  • Thanks for taking the time to help! A) For `sign_out_via` what exactly should I type? `sign_out_via = :delete ` right...? B) By convention should I run `Rails g controller User` or `Rails g controller Users`? Haha sorry I'm a newb and forget =(! – PrimeTimeTran Oct 05 '16 at 09:48
  • I did your suggestion of running `rails g controller Users` and then added this destroy method into the controller because I got an error saying I have no destroy method. https://gist.github.com/PrimeTimeTran/2ba75b382a8153ef04bc766658ac39bb Still doesn't delete(although I just copy and pasted the method from another App I made where destroy works. Should I code it differently since this is a session instead of an instance of a model? – PrimeTimeTran Oct 05 '16 at 10:07
  • I redid your steps again and I realized I made an error and you were right Pavan. I simply named it wrong. After doing `rails g controller Users` and adjusting my **devise.rb** file from `config.sign_out_via = :delete` to `config.sign_out_via = :get` to match the method parameter it worked. Thanks for the help! – PrimeTimeTran Oct 05 '16 at 16:27