I'm trying to get the display_cart function to properly total up the purchases and when I follow either the book or the downloaded code, I get the following error:
NoMethodError in BuyController#display_cart
undefined method `total' for #<Cart:0x1a327fc>
I've isolated the issue to the following area:
Code:
def display_cart
@cart = get_cart
@purchases = @cart.purchases
@total = @cart.total
end
When I replace @total = @cart.total with @total = @cart.price (I know that it isn't going to work) it displays the display cart view properly, sans the total. It seems the @total += item.price in
Code:
def add_purchase(item)
appendFlag = true
for purchase in @purchases
if (item.id == purchase.item.id)
appendFlag = false
purchase.quantity += 1
end
end
if(appendFlag)
@purchases << Purchase.buy_one(item)
end
@total += item.price
end
I am using Ruby 1.8.2 on Leopard (that's caused other errors) if it matters.
I'm sure it's very simple but I could use some extra help!