Yan Pritzker photographer, entrepreneur, software engineer, musician, skier

Blog :: Git Workflows Book :: Dotfiles :: Photography :: About Me

TwitterCounter for @skwp

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

hello, i'm yan

I am a photographer, entrepreneur, software engineer, guitarist, climber, and telemark skier

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

Enterprise intelligence with prediction markets

Find out what your team, colleagues and partners really know about the future — and leverage their knowledge to improve business decisions.

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

Archives

Contact

Reach me at yan at pritzker.ws

Multi column lists using in_groups_of

Posted 27 September 2006 @ 6am | Tagged RubyOnRails


Submit to HN

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