On 19 May 2010 13:20, the batman <[email protected]> wrote:
> I want to create a table displaying  image thumbnails, 3 per row.
> Can I use an if loop to create the <tr> tags?

"if" doesn't produce a loop - it's just a conditional check.

Assuming your images are stored in an array, you can use any of a
number of methods to loop them.

* you could do .each_with_index and then start a new row on mod-3 of the index
* you could use .each_slice(3) and iterate the returned array of three
* you could (if you like it clunky) just use .each maintain your own
counter and do your next row operations when it gets to a multiple of
3

http://www.ruby-doc.org/core/classes/Enumerable.html

> or is this better acheived with css?

Probably (for all sorts of "tables are for tabular data" reasons). But
the problem of working out how to tell the element it's a new row will
be very similar to using a table (unless you rely on overflow wrapping
in a fixed-size container).

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to