title: How to destroy an instance variable of one class within the controller of another class
body: <p>I'm doing the chapter exercises of Agile Web Development with Rails. It's a store with products which you can add to a cart.  A product inside a cart is called a LineItem.  You can delete individual line items inside the cart.  When the last line item is deleted I want the entire cart to be destroyed.  The code I have doesn't work:</p>
  
  <p><strong>CartsController</strong></p>
  
  <pre><code>def destroy
    @cart = current_cart
    @cart.destroy
    session[:cart_id] = nil
  
    respond_to do |format|
      format.html { redirect_to store_path }
      format.json { head :no_content }
    end
  end
  </code></pre>
  
  <p><strong>LineItemsController</strong></p>
  
  <pre><code>def destroy
    @cart = current_cart
    @line_item = LineItem.find(params[:id])
    quantity = @line_item.quantity
  
    if quantity &gt; 1
      quantity -= 1
      @line_item.update_attribute(:quantity, quantity)
    else
      @line_item.destroy
    end
  
    respond_to do |format|
      format.html {
        if @cart.line_items.empty?
          @cart.destroy
        else
          redirect_to @cart
        end
      }
      format.json { head :no_content }
    end
  end
  </code></pre>
  
  <p>This produces the following error:</p>
  
  <pre><code>Template is missing
  
  Missing template line_items/destroy, application/destroy with {:locale=&gt;[:en], :formats=&gt;[:html], :handlers=&gt;[:erb, :builder, :coffee]}. Searched in: * "/home/mike/Projects/depot/app/views"
  </code></pre>
  
  <p>When the cart is destroyed I want to end up at store_path.</p>
  
  <p>thanks,
  mike</p>