Forum: Ruby on Rails question about Agile Rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
588b8a8cef3c8231ff4cf6948d5e1991?d=identicon&s=25 Luciano Broussal (Guest)
on 2006-01-05 10:32
(Received via mailing list)
anyone can explain me why in the Agile Depot Tutorial application they
use i.product_id
to find if a product already exist in the cart, because the cart
contains items which each of them reference a product.

I tried i.product_id like in the tutorial
and
i.product.i

all of these 2 notation works , but i find the second s more clean.

Any explanation will be fine

Regards


def add_product(product)
    item = @items.find {|i| i.product_id == product.id} //and why not
i.product.id
    if item
      item.quantity +=1
    else
      @items << LineItem.for_product(product)
    end
    @total_price += product.price
  end
end
--


The Crocodile
This topic is locked and can not be replied to.