title: User signed in, but set to nil using Rails and Devise
body: <p>devise (4.4.0)
  Rails 5.1.4
  I'm seeing this question asked a lot, but not finding the answer that works for me. I am showing that I am signing up and logging in, but current user set to nil. I'm thinking maybe it is the cookies, but I'm having a hard time parsing exactly how to fix that. One solution suggested adding </p>
  
  <pre><code> Rails.application.config.session_store :cookie_store, key: '_bejoy_session', domain: :all
  </code></pre>
  
  <p>to the config > session_store.rb which I did not have, but created and included. I'm just not sure what I'm missing here. </p>
  
  <p>application controller:</p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    protect_from_forgery with: :exception
    before_action :configure_permitted_parameters, if: :devise_controller?
    helper_method :current_user
    helper_method :admin
  
    def current_user
      if session[:user_id]
        @current_user ||= User.find(session[:user_id])
      end
    end
  
    def authorize
      if !current_user
       flash[:alert] = "You aren't authorized to visit that page."
       redirect_to '/'
      end
    end
  
    def admin_authorize
      if !current_user || current_user.admin == false
       flash[:alert] = "Only administrators can visit that page."
       redirect_to new_user_session_path
      end
    end
  
    def admin
      current_user &amp;&amp; current_user.admin
    end
  
    protected
      def configure_permitted_parameters
        devise_parameter_sanitizer.permit(:sign_up, keys: [:username, :admin, :email])
      end
   end
  </code></pre>
  
  <p>routes.rb</p>
  
  <pre><code>Rails.application.routes.draw do
    root :to =&gt; 'contents#index'
    resources :contents
    resources :visitors
  
    devise_for :users, controllers: {
      sessions: 'users/sessions',
      passwords: 'users/passwords',
      registrations: 'users/registrations'
    }
  end
  </code></pre>
  
  <p>Terminal:</p>
  
  <pre><code>Started POST "/users/sign_in" for 127.0.0.1 at 2018-01-07 12:31:25 -0800
  Processing by Users::SessionsController#create as HTML
  Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"6a0yiBCkmEN0W68xN/lVZH71YhT5i5tMEkFFYqnoIvMU0NJjH3LM3hPG+8yO3D1tXskh9pSA+PRFVKDmiKzN6A==", "user"=&gt;{"email"=&gt;"test@tester.com", "password"=&gt;"[FILTERED]", "remember_me"=&gt;"0"}, "commit"=&gt;"Log in"}
  User Load (1.9ms)  SELECT  "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["email", "test@tester.com"], ["LIMIT", 1]]
  (0.1ms)  BEGIN
  SQL (2.0ms)  UPDATE "users" SET "current_sign_in_at" = $1, "last_sign_in_at" = $2, "sign_in_count" = $3, "updated_at" = $4 WHERE "users"."id" = $5  [["current_sign_in_at", "2018-01-07 20:31:26.091228"], ["last_sign_in_at", "2018-01-07 20:29:10.402839"], ["sign_in_count", 5], ["updated_at", "2018-01-07 20:31:26.092407"], ["id", 2]]
  (0.4ms)  COMMIT
  Redirected to http://localhost:3000/
  Completed 302 Found in 152ms (ActiveRecord: 4.5ms)
  
  
  Started GET "/" for 127.0.0.1 at 2018-01-07 12:31:26 -0800
  Processing by ContentsController#index as HTML
  User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 2], ["LIMIT", 1]]
  **current_user :nil
  session id request :353a5e1d2bd295e8ac665e22e8f31314
  user_signed_in? :false**
  Rendering contents/index.html.erb within layouts/application
  Content Load (0.2ms)  SELECT "contents".* FROM "contents"
  Rendered contents/index.html.erb within layouts/application (1.5ms)
  Rendered partials/_author_photo_contact_block.html.erb (0.4ms)
  Completed 200 OK in 53ms (Views: 49.1ms | ActiveRecord: 0.5ms)
  </code></pre>
  
  <p>contents controller:</p>
  
  <pre><code>class ContentsController &lt; ApplicationController
     before_action :authenticate_user!
     # before_action :set_content, only: [:show, :edit, :update, :destroy]
  
     def index
        @contents = Content.all
        logger.debug "current_user :#{current_user.inspect}"
        logger.debug "session id request :#{request.session_options[:id]}"
        logger.debug "user_signed_in? :#{user_signed_in?}"
     end
  
     def show
     end
  
     def new
       @content = Content.new
     end
  
     def edit
     end
  
     def create
       @content = Content.new(content_params)
  
       respond_to do |format|
         if @content.save
           format.html { redirect_to @content, notice: 'Content was successfully created.' }
           format.json { render :show, status: :created, location: @content }
         else
           format.html { render :new }
           format.json { render json: @content.errors, status: :unprocessable_entity }
         end
       end
     end
  
     def update
       respond_to do |format|
         if @content.update(content_params)
           format.html { redirect_to @content, notice: 'Content was successfully updated.' }
           format.json { render :show, status: :ok, location: @content }
         else
           format.html { render :edit }
           format.json { render json: @content.errors, status: :unprocessable_entity }
         end
       end
     end
  
     def destroy
       @content.destroy
       respond_to do |format|
         format.html { redirect_to contents_url, notice: 'Content was successfully destroyed.' }
         format.json { head :no_content }
       end
     end
  
     private
       def set_content
         @content = Content.find(params[:id])
       end
  
       def content_params
         params.require(:content).permit(:main_image, :sidebar_image, :content, :sidebar)
       end
   end
  </code></pre>