Splitting records into multiple columns (can this code be im


#1

I have an array of categories, and I wanted them split
up into two columns in tables:

category item_count | category item_count
category item_count | category item_count
category item_count | category item_count
category item_count | category item_count

Here’s the template code:

<% table_break=(@categories.length.to_f/2).ceil %> <% i=1 %> <% for category in @categories %> <% if i==table_break %>
<%= link_to h(category.name), {:controller=>'categories', :action=>'list', :category=>category.key} %> <%= category.item_count %>
<% end %> <% i+=1 %> <% end %>

Anybody have a simpler way? :slight_smile: If it was possible to
do ‘for index category in @categories’ (or in its
.each incantation), that’d eliminate the i var, but I
don’t see anything like that in Ruby’s docs. I also
had ‘table_break=(@categories.length/2).ceil’, but
apparently Ruby truncates (@categories.length/2)?

thanks
csn


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com