skeeterbug, I have updated to Rails 1.2 but still have the same issue you have. I am using Ruby 1.8.5, does anyone know if that may be the problem? The second edition of "Agile Web Dev with Rails" recommended using 1.8.4. Also, I used InstantRails to setup my environment and then updated to Rails 1.2 (beta)
What is more, when I look in the Ruby Documentation I don't see a "sum" method for Array...am I correct? That may explain why we are both getting the error:
"undefined method `sum' for #<Array:0xb793d290>" :-)
See if you can wade through this fix dated 05/03/2006 by Ron Jefferies who says "Of course there is no sum method in Array..." about a third the way down the page:
http://www.xprogramming.com/xpmag/dbcBowlingVector.htm
But in the meantime, here is my -- rather naive -- temporary fix, but it works. In the Cart class, modify the the def total_price method...
FROM:
def total_price
@items.sum { |item| item.price }
end
TO:
def total_price
sum = 0
for item in @items
sum += Float(item.price)
end
return sum
end
I also tried:
def total_price
@items.inject(0) { |sum, item.price| sum + item.price}
end
but got the error: "CartItem can't be coerced into Fixnum"
If anyone knows how to resolve this please let me know.
Thanks
Bookmarks