title: Why is current_user giving me an error?
body: <p>In my create method in the Videos controller, this line works:</p>
  
  <pre><code>@video = Video.new(params[:video])
  </code></pre>
  
  <p>However, I want to assign the video to the user, so I use this line which gives me an error:</p>
  
  <pre><code>@video = current_user.videos.new(params[:video])
  </code></pre>
  
  <p>This is the error:</p>
  
  <pre><code>NoMethodError in VideosController#create
  
  undefined method `videos' for nil:NilClass
  </code></pre>
  
  <p>I have this in my User model:</p>
  
  <pre><code>has_many :videos
  </code></pre>
  
  <p>And this in my Video model:</p>
  
  <pre><code>belongs_to :user
  </code></pre>
  
  <p>This is in my application_controller file:</p>
  
  <pre><code>  def current_user
      return unless session[:user_id]
      @current_user ||= User.find_by_id(session[:user_id]) 
    end
  
    # Make current_user available in templates as a helper
    helper_method :current_user
  </code></pre>
  
  <p>How do I fix this error? Let me know if I should post anymore code.</p>