Forum: Ruby on Rails Agile Depot Tutorial Help

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:56
(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,  each of them references 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 seems more
clean??? isn't it.

Any explanation will be fine

Regards
205bc8d44e9bc5c68d77dd412abcb3ce?d=identicon&s=25 Dan Shafer (Guest)
on 2006-01-06 00:49
(Received via mailing list)
I"m a Nuby so I could be wrong....

What this code is doing is just checking for the existence of a
product corresponding to the value stored in "i". It doesn't matter
what attribute of that product you ask for, the result will be the
same. Presuming products have a name attribute, you could as easily
write

i.product.name

and get the same result.

product_id is one of those amazing Rails freebies that just makes
good coding sense to use.

At least that's my take.

On Jan 5, 2006, at 1:53 AM, Luciano Broussal wrote:

> clean??? isn't it.
>
> Any explanation will be fine
>
> Regards
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
Dan Shafer
Technology Visionary - Technology Assessment - Documentation
"Looking at technology from every angle"
http://www.eclecticity.com
6661ef9d747db3af8896cd94959d717d?d=identicon&s=25 Paul Barry (Guest)
on 2006-01-06 15:45
(Received via mailing list)
i.product_id and i.product.id both work because the LineItem object has
a
product_id Integer property and a project Product property.  It gets the
product_id property from the line_item database table, product_id colum.
The project property comes from the belongs_to in the LineItem class
defined
in app/models/line_items.rb
This topic is locked and can not be replied to.