Each print <br> after a few iterations

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 %>

Regards,
Joris

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

<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