I want to generate a table of images, something like:

<I> <I> <I>
<I> <I> <I>

So I've to put a <br> after 3 iterations, how should I do this?

I could make a counter initialize it on zero, increment its value and
check it for "mod3=0", but I think there might be a better way to do it
in ruby?

I've something like:

<% @games.each do |game| %>

   <%= link_to image_tag(game.image.url), game %>

<% end %>

Couple of options... you could do each_with_index and then print a <br> if i % 3 == 0. You might not get a <br> on the last line though.

Or you could use in_groups_of which is meant for this sort of thing.

http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Array/Grouping.html

--
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 rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to