Last active
December 9, 2015 21:08
-
-
Save reggieb/4328455 to your computer and use it in GitHub Desktop.
Split a collection of items so that they can be displayed within two column divs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% number_of_columns = 2 %> | |
<div class="columns"> | |
<% @things.each_slice((@things.length / number_of_columns.to_f).ceil) do |column_of_things| %> | |
<div class ="column"> | |
<% column_of_things.each do |thing| %> | |
<%= thing.title %> | |
<% end %> | |
</div> | |
<% end %> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using ceil to handle overflow from division, gives more flexibility, and allows the same pattern to be used for 3, 4 or more columns.