title: Undefined method '' for nil:NilClass
body: <p>Just trying to make a simple shopping cart for an application selling bikes using ruby. This error has me bogged down so any help would be very appreciated! </p>
  
  <p>The error comes up when I want to add something to the cart. Its something to do with my controller of the lineitems or my cart model.</p>
  
  <p>For my line items:</p>
  
  <pre><code>@lineitem = @cart.add_bike(bike.id)
  </code></pre>
  
  <p>For my model:</p>
  
  <pre><code>def add_bike(bike_id)
    current_item = lineitems.find_by_bike_id(bike_id)
    if current_item
      current_item.quantity +=1
    else
      current_item = lineitems.new(bike_id: bike_id)
      current_item.quantity = 1
    end
    current_item          #this is returning the current_item object  
  end
  </code></pre>
  
  <p>My error in full is <code>undefined method `add_bike' for nil:NilClass</code></p>
  
  <pre><code>def current_cart
    @cart = Cart.find(session[:cart_id])
    rescue ActiveRecord::RecordNotFound
      @cart = Cart.create
      session[:cart_id] = @cart.id
    end
  end
  </code></pre>