skwpspace yan pritzker’s home on the web

skwpspace is Yan Pritzker's home on the web

Blog :: Photography :: About Me

TwitterCounter for @skwp

Get the news feed
Get updates by email
Follow me on twitter

hello, i'm yan

This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.

Top Posts

planypus

I'm the founder of Planypus, the place to share your plans!

cohesiveft

Accessible, manageable, virtualized application stacks ready to download or deploy to the cloud!

flickr

smokingThe old man and the accordionBicycle 6x6Eva 6x6Shaffies 6x6Phone Booth Velvia 6x6WynnStar 6x6

Archives

Contact

Reach me at yan at pritzker.ws

Posted
27 September 2006 @ 6am

Tagged
RubyOnRails

Multi column lists using in_groups_of

This code uses the basic technique outlined in this article to split the list up into several lists of a fixed size and then use css to float them into columns.


<% col_size = friends.size/4 %>
<% friends.in_groups_of(col_size) do |group| %>
  <div class=list>
    <ul>
    <% group.each do |friend| %>
      <li><%= display friend %></li>
    <% end %>
    </ul>
  </div>
<% end %>


div.list {
 width: 10em;
 float: left;
}

1 Comment

Posted by
Jeroen Knoops
28 November 2007 @ 7am

Thank you for this post, but I think this is not yet finished. If the number of friends is 9 you will get 5 columns instead of 4.

I’ve posted this code on http://refactormycode.com/codes/167-split_in_groups-instead-of-in_groups_of to see if people have a similar problem.


Leave a Comment

Dynamically adding instance methods for fun and profit Multi column list Rails helper