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
# 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 ==}
if item
item.quantity += 1
item = LineItem.for_product(product)
@items << item
@total_price += product.price

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 but how and
where product_id is defined in the hash is not clear to me.

*** e-mail is not a secure channel ***
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 ==}

Try this instead

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


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs