Agile tutorial

Thank you for the comments on conditional replacements. I now have
another oddity to deal with.

When adding products to the session cart I am not able to have the
count incremented if the product has already been selected, rather
another item is added to the cart. I copied the code from the book
as carefully as I could and could find no error but to be sure I
then cut and pasted the code file from the rails development site
and obtained the same result.

my app/models/cart.rb file presently looks like this:

class Cart
attr_reader :items
attr_reader :total_price
def initialize
@items = []
@total_price = 0.0
end
# add a product to our list of items. If an item already
# exists for that product, up the count instead
def add_product(product)
item = @items.find {|i| i.product_id == product.id}
if item
item.quantity += 1
else
item = LineItem.for_product(product)
@items << item
end
@total_price += product.price
end
end

Is there any other place that I should be looking? What I am
getting for output is this:

Display Cart

Your cart currently holds 2 items.
1.0 Development Product 03 14.34 14.34
1.0 Development Product 03 14.34 14.34

I realize that this is not much to go on but any pertinent
suggestions that anyone can make would be appreciated. It is
evident that i.product_id is never equal to product.id but how and
where product_id is defined in the hash is not clear to me.


*** e-mail is not a secure channel ***
mailto:byrnejb.@harte-lyne.ca
James B. Byrne Harte & Lyne Limited
vox: +1 905 561 1241 9 Brockley Drive
fax: +1 905 561 0757 Hamilton, Ontario
= hal Canada L8E 3C3

James B. Byrne wrote:

item = @items.find {|i| i.product_id == product.id}

Try this instead

item = @items.find {|i| i.id == product.id}

_Kevin