Re: ruby on rails book, fundamental question

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
otherwise you have to loop through them.

--------- Original Message --------
From: [email protected]
To: [email protected] [email protected]
Subject: Re: [Rails] ruby on rails book, fundamental question
Date: 17/04/06 17:58

I will try to explain this.  If you do the same command from
./script/console "@products = Product.find(:all)", you will be
able to access this hash by calling each element as @products[1].title
or by
other keys in the hash.  Does that make since?
JohnOn 4/17/06, Jan <[email protected]> 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
list   @products = paginate :product, :per_page => 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
solution is to do it like this (like in the book)
<% for product in @products
-%>        <img
src="<%= product.image_url %>"/><% end %>But I
to understand (!) how this works. Something like
[email protected]["title"] or puts @products[:title] which
work.I think this would help to understand the whole concept.Thanks
alot–Posted via
Rails mailing
[email protected]://

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