joris
1
I want to generate a table of images, something like:
So I’ve to put a
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
joris
2
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
if i % 3 == 0. You might not get a
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