title: undefined method 'name' for nil:NilClass, but I know the record exists
body: <p>I am trying to build a simple cart based on sessions. I am using this youtube tutorial as an template: vid#4 here <a href="https://www.youtube.com/watch?v=WRVwfVUaj_Y" rel="nofollow">https://www.youtube.com/watch?v=WRVwfVUaj_Y</a> and vid#5 here <a href="https://www.youtube.com/watch?v=HSMqi913SL4" rel="nofollow">https://www.youtube.com/watch?v=HSMqi913SL4</a>. </p>
  
  <p>I am getting the same error that he gets in vid#5 at   , but he doesn't show how he fixed it. </p>
  
  <p>Here are my routes:</p>
  
  <pre><code>get '/cart' =&gt; 'cart#index'
  get '/cart/clear' =&gt; 'cart#clearCart'
  get '/cart/:id' =&gt; 'cart#add'
  </code></pre>
  
  <p>And here is my cart_controller.rb:</p>
  
  <pre><code>class CartController &lt; ApplicationController
  
    def add
      id = params[:id]
  
      if session[:cart] then
        cart = session[:cart]
      else
        session[:cart] = {}
        cart = session[:cart]
      end
  
      if cart[id] then
        cart[id] = cart[id] + 1
      else
        cart[id] = 1
      end
  
      redirect_to :action =&gt; :index
    end
  
    def clearCart
      session[:cart] = nil
      redirect_to :action =&gt; :index
    end
  
    def index
  
  
      if session[:cart] then
        @cart = session[:cart]
      else
        @cart = {}
      end
    end
  end
  </code></pre>
  
  <p>Here is my cart/index.html.erb page:</p>
  
  <pre><code>&lt;h3&gt;Your Shopping Cart&lt;/h3&gt;
  
  &lt;%= link_to "Empty Your Cart", cart_clear_path %&gt;
  
  &lt;% total = 0 %&gt;
  
  &lt;% @cart.each do | id, quantity | %&gt;
      &lt;% product = Product.find_by_id(id)%&gt;
  
  &lt;div class="row"&gt;
      &lt;div class="col-lg-3 col-md-3 col-sm-6 col-xs-12" &gt;
  
          &lt;div class="product_text"&gt;
              &lt;h3&gt;&lt;%= product.name %&gt;&lt;/h3&gt;
              &lt;h3&gt;&lt;%= product.description %&gt;&lt;/h3&gt;
              &lt;h3&gt;$&lt;%= product.price %&gt;&lt;/h3&gt;
  
  
          &lt;/div&gt;  
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;%end%&gt;
  </code></pre>
  
  <p>I am very confused because I know the Product object exists, but I am still getting the error in title. </p>