Is there a way to traverse an array and perform an action (like
collect) in sets? I am trying to use an array to populate a table
with three cells per row, so I need to pop in sets of three, then
create a new row.
Thanks,
JB
Is there a way to traverse an array and perform an action (like
collect) in sets? I am trying to use an array to populate a table
with three cells per row, so I need to pop in sets of three, then
create a new row.
Thanks,
JB
On 8/23/07, Jables [email protected] wrote:
Is there a way to traverse an array and perform an action (like
collect) in sets? I am trying to use an array to populate a table
with three cells per row, so I need to pop in sets of three, then
create a new row.
you need the method in_groups_of. Here’s how I use it
<table>
<% @products.in_groups_of(2, ' ') do |item| -%>
<tr class="<%= cycle("item0","item1") %>">
<% item.each do |item| next unless
item.respond_to?(:product_name) -%>
<%= item.product_name %>
<% end -%>
<% end -%>
Thanks Adam.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs