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:
CartsController
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
LineItemsController
def destroy
@cart = current_cart
@line_item = LineItem.find(params[:id])
quantity = @line_item.quantity
if quantity > 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
This produces the following error:
Template is missing
Missing template line_items/destroy, application/destroy with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/mike/Projects/depot/app/views"
When the cart is destroyed I want to end up at store_path.
thanks,
mike
See the addition (as a comment):