2

I am a bit new to Ruby (v2.0.0) on Rails (v4.0.0) and Devise (v3.5.2), and for some reason I cannot Sign Out once I have Signed Up. However, if I manually go into the MySQL2 database and completely delete the user, my Sign Up/Sign In page becomes available again.

I have not touched my session_store.rb initializer or anything else. I am in dire straits and need this fixed before I can move forward.

Help is greatly appreciated.

The logic for my Sign Up form is very simple:

<% if user_signed_in? %>
    <%= current_user.email %> / <%= link_to "Sign Out", destroy_user_session_path, method: :delete %>
<% else %>
    <%= link_to "Sign Up", new_user_registration_path %> / <%= link_to "Log In", new_user_session_path %>
<% end %> 

My devise.rb file is also configured to use :delete :

config.sign_out_via = :delete

I have JQuery in my Gemfile:

# jQuery
gem 'jquery-rails'
gem 'jquery-ui-rails'

And I have them initialized in application.js:

//= require jquery
//= require jquery_ujs
//= require jquery.ui.all
//= require jquery.details
//= require jquery.textchange

My routes.rb is properly configured (the commented out "#devise_for :users" shows that I have tried both methods, none worked) :

Selfstarter::Application.routes.draw do
root :to => 'home#index'
  #devise_for :users
  devise_for :users do
  get '/users/sign_out' => 'devise/sessions#destroy'
  end
...
end

And my rake routes reflects that:

                  Prefix Verb     URI Pattern                     Controller#Action
                    root GET      /                               home#index
        new_user_session GET      /users/sign_in(.:format)        devise/sessions#new
            user_session POST     /users/sign_in(.:format)        devise/sessions#create
    destroy_user_session DELETE   /users/sign_out(.:format)       devise/sessions#destroy
           user_password POST     /users/password(.:format)       devise/passwords#create
       new_user_password GET      /users/password/new(.:format)   devise/passwords#new
      edit_user_password GET      /users/password/edit(.:format)  devise/passwords#edit
                         PATCH    /users/password(.:format)       devise/passwords#update
                         PUT      /users/password(.:format)       devise/passwords#update
cancel_user_registration GET      /users/cancel(.:format)         devise/registrations#cancel
       user_registration POST     /users(.:format)                devise/registrations#create
   new_user_registration GET      /users/sign_up(.:format)        devise/registrations#new
  edit_user_registration GET      /users/edit(.:format)           devise/registrations#edit
                         PATCH    /users(.:format)                devise/registrations#update
                         PUT      /users(.:format)                devise/registrations#update
                         DELETE   /users(.:format)                devise/registrations#destroy

user.rb Model:

class User < ActiveRecord::Base
  has_many :orders
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
end

database.rb just in case it's needed:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: dbname
  pool: 5
  username: dbusername
  password: dbpass
  #socket: /opt/local/var/run/mysql5/mysqld.sock

I am at a loss as to what to what steps to take next, and have scoured Google and Stack Overflow. I found nothing.

I also want to mention that I would really want to stick to RESTful conventions, and would not like to use :get methods if at all possible.

EDIT: My Log File

Started DELETE "/users/sign_out" for 127.0.0.1 at 2015-08-21 11:28:17 -0400
Started DELETE "/users/sign_out" for 127.0.0.1 at 2015-08-21 11:28:17 -0400
Processing by Devise::SessionsController#destroy as HTML
Processing by Devise::SessionsController#destroy as HTML
  User Load (3.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
  User Load (3.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
Can't verify CSRF token authenticity
Can't verify CSRF token authenticity
   (1.0ms)  BEGIN
   (1.0ms)  BEGIN
   (1.0ms)  COMMIT
   (1.0ms)  COMMIT
Redirected to http://localhost:3000/
Redirected to http://localhost:3000/
Completed 302 Found in 66ms (ActiveRecord: 5.0ms)
Completed 302 Found in 66ms (ActiveRecord: 5.0ms)
aishaq11
  • 179
  • 1
  • 1
  • 16
  • post what you have in your logs while requesting logout link please – Avdept Aug 21 '15 at 15:20
  • This is going to sound stupid but how do I access my log? My development.log file in my log directory is empty, and my command line loses lots of information when I preform an action because it scrolls down so much, so I can't see a whole lot. – aishaq11 Aug 21 '15 at 15:23
  • Are you able to see the Sign Out link at all? If yes, like @Avdept mentionned, please post the logs when you request the logout link – Alexandre Voyer Aug 21 '15 at 15:23
  • Yes I am able to see my links Alexandre. See my above comment with my stupid log problem. – aishaq11 Aug 21 '15 at 15:26
  • Just checking, but have you restarted your server after installing `Devise` and all that? – vich Aug 21 '15 at 15:28
  • Yes I have restarted the server many times. Also I have edited my log output at the bottom of my initial post. – aishaq11 Aug 21 '15 at 15:30
  • See this question for CRSF token issues like that you're having: http://stackoverflow.com/questions/11845500/rails-devise-authentication-csrf-issue – RichardAE Aug 21 '15 at 15:40
  • I have tried this already, it did not work unfortunately. – aishaq11 Aug 21 '15 at 17:13
  • Also put your destroy action please.Its not clear whats happens there – Avdept Aug 21 '15 at 20:17
  • Is there supposed to be a destroy action? I am using the Devise gem, I thought it was built into that, so I don't exactly have a Users controller. – aishaq11 Aug 24 '15 at 14:35
  • Solved, answer is below. – aishaq11 Sep 03 '15 at 15:06

1 Answers1

0

I have finally discovered the solution. I merely had to add <%= csrf_meta_tags %> into my application.html.erb header tags and it worked like a charm.

aishaq11
  • 179
  • 1
  • 1
  • 16