title: undefined local variable or method `current_user' cancancan
body: <p>I'm working on a login/logout system. Instead of using devise, I created an active records User model and use sessions to remember if a user is logged in. Everything was working fine until I added these lines in the <code>application_controller.rb</code> to have a layout before login and one after.</p>
  
  <pre><code>layout :set_layout
    def set_layout
      if session[:current_user_id]
        'afterlogin'
      else
        'application'
      end
    end 
  </code></pre>
  
  <p>Now, after I log in and <code>cancancan</code> is being used somewhere in a html page I get <code>undefined local variable or method 'current_user'</code>. I think that I have to add a <code>current_user</code> method but I'm not exactly where and how to define it. </p>
  
  <p>Edit: I already had something similar in another class that is being used by login: </p>
  
  <pre><code>class Admin::ApplicationController &lt; ApplicationController
      before_action :authorize
  
    def authorize
    begin
      @current_user ||= User.find(session[:current_user_id]) if session[:current_user_id]
    rescue ActiveRecord::RecordNotFound
      session.destroy
      redirect_to '/login',alert: 'Please login'
    end
  end
  
  end
  </code></pre>
  
  <p>Should I modify this after I add that method ? </p>