From: Matt Todd Date: 2006-08-02T13:45:52+09:00 Subject: Re: Rails view template for a gallery I'll be honest, I think this is Ruby-centric enough because it really comes down to basic looping and Erb, so I'll take a stab at it!

<%= @gallery.name -%>

<% ((@gallery.length / 4) + (((@gallery.length % 4) > 0) ? 1 : 0)).downto(1) do %> <% 4.downto(1) do %> <% end %> <% end %>
That basically figures out how many rows (based on the length divided by 4, plus 1 if there were any leftovers) and then loops through them. Then, for each row, we loop four times and for each iteration, we shift off the front element to go from beginning to end (instead of pop, which will pull if off the end). I like this solution a bit better because it uses a very heirarchical structure much like the way the data will be. Plus, I don't have to embed any HTML into Erb! Hope this helps, M.T.