Either the rails only way:
some_array.in_groups_of(2)
which pads with nil, or the more ruby way:
require 'enumerator'
some_array.slice(2)
Cheers, Max
Either the rails only way:
some_array.in_groups_of(2)
which pads with nil, or the more ruby way:
require 'enumerator'
some_array.slice(2)
Cheers, Max
Use in place of some_list.each. Instead of
<% for thing in list %> ... render stuff ... <% end %>
use
<% list.in_groups_of(2) do |two_things| %> <tr> <td><%= two_things[0].some_attribute if two_things[0] %></td> <td><%= two_things[1].some_attribute if two_things[1] %></td> </tr> <% end %>
The nil check is necessary, as in_groups_of pads the last "row" with nils if there are not enough elements in the list.
BTW, googling for "rails in_groups_of" would have gotten you there as well...
Cheers, Max