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
--
Posted via http://www.ruby-forum.com/.
--
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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.