Forum: Ruby on Rails Re: ruby on rails book, fundamental question

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.
Eb68334737855f297a8b917d3cfe6adb?d=identicon&s=25 Ian Roke (Guest)
on 2006-04-17 15:04
(Received via mailing list)
If you write out the loop in long hand it makes more sense.

for each item in products array

item dot title =

next item

If you know the id in particular you want to show you can do
item[1].title
otherwise you have to loop through them.

--------- Original Message --------
From: rails@lists.rubyonrails.org
To: rails@lists.rubyonrails.org <rails@lists.rubyonrails.org>
Subject: Re: [Rails] ruby on rails book, fundamental question
Date: 17/04/06 17:58

> I will try to explain this.&nbsp; If you do the same command from
./script/console &quot;@products = Product.find(:all)&quot;, you will be
able to access this hash by calling each element as @products[1].title
or by
other keys in the hash.&nbsp; Does that make since?
> JohnOn 4/17/06, Jan &lt;shocktone@lycos.de&gt; wrote:
> Hi guys,bought the ROR book. I understand most of it and really like it.
Thereis just on thing I just dont get.Lets take this code for
example.def
list&nbsp;&nbsp; @products = paginate :product, :per_page =&gt; 10
> endAs far as I understand @products should be some kinda hash or
array,with the data of the Database inside.How can I display this array
?One
solution is to do it like this (like in the book)
> &lt;% for product in @products
-%&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;img
src=&quot;&lt;%= product.image_url %&gt;&quot;/&gt;&lt;% end %&gt;But I
want
to understand (!) how this works. Something like
puts@products[&quot;title&quot;] or puts @products[:title] which
obviously
doesnt
> work.I think this would help to understand the whole concept.Thanks
alot--Posted via
http://www.ruby-forum.com/._______________________...
> Rails mailing
listRails@lists.rubyonrails.orghttp://lists.rubyonrails.org/mailman/listinfo/rails
This topic is locked and can not be replied to.