Forum: Ruby on Rails Splitting records into multiple columns (can this code be im

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 CSN (Guest)
on 2005-12-14 00:23
(Received via mailing list)
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>
  <tr valign="top">
    <td width="50%">
      <table width="100%">
        <%
table_break=(@categories.length.to_f/2).ceil %>
        <% i=1 %>
        <% for category in @categories %>
        <tr>
        <td nowrap><%= link_to h(category.name),
   {:controller=>'categories', :action=>'list',
:category=>category.key} %></td>
        <td align="right"><%= category.item_count
%></td>
        </tr>
        <% if i==table_break %></table></td><td
width="50%" nowrap><table width="100%"><% end %>
        <% i+=1 %>
        <% end %>
      </table>
    </td>
  </tr>
</table>

Anybody have a simpler way? :) 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
This topic is locked and can not be replied to.