title: undefined method `admin?' for nil:NilClass
body: <p>I followed <a href="http://railscasts.com/episodes/250-authentication-from-scratch-revised" rel="noreferrer">railscast #250 Authentication from Scratch</a> &amp; got everthing wworking fine.  Now I'm trying to only display edit &amp; destroy links on my index page to admin user's.</p>
  
  <p>I've set up mu User database with a admin boolean field &amp; tried putting a simple if statement in the view of another model (hikingtrails) to only display certain links to admin users but I get this error when I try it out, <code>undefined method 'admin?' for nil:NilClass</code></p>
  
  <h2>Database Schema</h2>
  
  <pre><code>  create_table "users", :force =&gt; true do |t|
      t.string   "email"
      t.string   "password_digest"
      t.boolean  "admin"
      t.datetime "created_at",      :null =&gt; false
      t.datetime "updated_at",      :null =&gt; false
    end
  </code></pre>
  
  <h2>User Model</h2>
  
  <pre><code>class User &lt; ActiveRecord::Base
    attr_accessible :email, :password, :password_confirmation#, :admin
  
    validates :email, :uniqueness =&gt; true
  
    has_secure_password
  end
  </code></pre>
  
  <h2>Application Controller</h2>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    protect_from_forgery
  
    # fetch the currently logged-in user record to see if the user is currently logged in
    # putting this method in ApplicationController so that it’s available in all controllers
    private
    def current_user
      # checks for a User based on the session’s user id that was stored when they logged in, and stores result in an instance variable
      @current_user ||= User.find(session[:user_id]) if session[:user_id]
    end
    # to give access to this method from all the views, the helper_method makes it a helper method
    helper_method :current_user
  
    # basic authorization, user must be logged in!
    def authorize
      redirect_to login_url, alert: "You must be logged in to perform this action" if current_user.nil?
    end
  end
  </code></pre>
  
  <h2>views/hikingtrails/index.html.erb</h2>
  
  <pre><code>  &lt;% if current_user.admin? %&gt;
      &lt;%= link_to t('.edit', :default =&gt; t("helpers.links.edit")),
                edit_hikingtrail_path(hikingtrail), :class =&gt; 'btn btn-mini' %&gt;
      &lt;%= link_to t('.destroy', :default =&gt; t("helpers.links.destroy")),
                hikingtrail_path(hikingtrail),
                :method =&gt; :delete,
                :data =&gt; { :confirm =&gt; t('.confirm', :default =&gt; t("helpers.links.confirm", :default =&gt; 'Are you sure?')) },
                :class =&gt; 'btn btn-mini btn-danger' %&gt;
    &lt;% end %&gt;
  </code></pre>