title: Cannot access "Current user" in rails
body: <p>I am using devise and devise_ldap for my rails authentication. I am trying to use the built in helper, current user to display the users email on the welcome page of my application.
  This is the code that I have tried to use to:</p>
  
  <pre><code>&lt;% if user_signed_in? %&gt;
   &lt;div&gt;Signed in as... &lt;%= current_user.email %&gt;&lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>when I sign in to the application, I get the error;</p>
  
  <pre><code>undefined method `email' for nil:NilClass
  </code></pre>
  
  <p>Here is my routes.rb </p>
  
  <pre><code>Rails.application.routes.draw do
  
   devise_for :users
   resources :users
   resources :systems do
    member do
     get :targets, :sources
   end
   root      'systems#index'
  end
  </code></pre>
  
  <p>and my users controller:</p>
  
  <pre><code>class UsersController &lt; ApplicationController
  authorize_resource
  before_action :set_user, only: [:show, :edit, :update, :destroy]
  
  # GET /users
  def index
  @users = User.all.order("display_name asc")
  end
  
  # GET /users/1
  def show
  end
  
  # GET /users/new
  def new
      @user = User.new
  end
  
  # GET /stories/1/edit
  def edit
      respond_to do |format|
        format.html
        format.js
      end
  end
  
  # POST /stories
  def create
  @user = User.new(user_params)
      respond_to do |format|
         puts 'user controller'
        if @user.save!
          format.html { redirect_to user_path(@user), notice: 'User was successfully created.' }
        else
          format.html { render :new }
        end
      end
  end
  
  # PATCH/PUT /stories/1
  def update
      respond_to do |format|
        if @user.update(user_params)
          format.html { redirect_to user_path(@user), notice: 'User was successfully updated.' }
        else
          format.html { render :edit }
        end
      end
  end
  
  # DELETE /stories/1
  def destroy
  @user.destroy
  respond_to do |format|
    format.html { redirect_to users_path notice: 'User was successfully destroyed.' }
  end
  end
  
  private
  # Use callbacks to share common setup or constraints between actions.
  def set_user
    @user = User.find(params[:id])
  end
  
  
  
  # Never trust parameters from the scary internet, only allow the white list through.
  def user_params
     params.require(:user).permit(:display_name, :email, :username)
  end
  end
  </code></pre>
  
  <p>my users model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  before_create :rememberable_value
  
  before_save :get_ldap_values
  
  devise :ldap_authenticatable, :rememberable, :trackable, :validatable
  
  def get_ldap_values
    if self.username
      self.email = Devise::LDAP::Adapter.get_ldap_param(self.username,"mail").first if Devise::LDAP::Adapter.get_ldap_param(self.username,"mail")
      self.display_name = Devise::LDAP::Adapter.get_ldap_param(self.username,"displayName").first if Devise::LDAP::Adapter.get_ldap_param(self.username,"displayName")
    end
  end
  
  # def role?(role)
  #     return !!self.roles.find_by_name(role.to_s.camelize)
  # end
  
  def email_required?
      false
  end
  
  def email_changed?
      false
  end
  def rememberable_value
      self.remember_token ||= Devise.friendly_token
  end
  
  def name_to_display
      if self.display_name
          self.display_name
      else
          self.username
      end
  end
  
  def password_required?
      false
  end
  
  def password_match?
      self.errors[:password] &lt;&lt; "can't be blank" if password.blank?
      self.errors[:password_confirmation] &lt;&lt; "can't be blank" if password_confirmation.blank?
      self.errors[:password_confirmation] &lt;&lt; "does not match password" if password != password_confirmation
      password == password_confirmation &amp;&amp; !password.blank?
  end
  end
  </code></pre>
  
  <p>I am not sure what I am missing to be able to access the current users information after a successful sign in.</p>
  
  <p><strong>Update</strong></p>
  
  <p>Here is the new routes file:</p>
  
  <pre><code>Rails.application.routes.draw do
  
  
  devise_scope :user do
   get '/users/sign_out' =&gt; 'devise/sessions#destroy'
   get "/users/sign_in" =&gt; "devise/sessions#new"
   # delete "/logout" =&gt; "devise/sessions#destroy"
  end
  
  devise_for :users
  authenticate(:user) do
   resources :users
   resources :reports
   resources :change_logs, only: [:index, :show]
   resources :systems do
    member do
      get :targets, :sources
    end
    resources :change_logs, module: :systems
    resources :components do
      resources :change_logs, module: :components
    end
    resources :c_relations
   end
  
   resources :integrations
    get '/static_pages/home'  # =&gt; 'static_pages#home', as: 'home'
   root      'systems#index'
  end
  </code></pre>