Ruby on Rails Splitting or Slicing list into columns -


@locations = location.all #current listing  @locations = location.slice(5) or location.split(5) 

with ruby i'm trying split list 4 columns, limiting each column 5 each; neither slicing or splitting seems work. idea of might doing wrong? appreciated.

you want use in_groups_of:

http://railscasts.com/episodes/28-in-groups-of

here's ryan bates' example usage railscast:

<table> <% @tasks.in_groups_of(4, false) |row_tasks| %>   <tr>     <% task in row_tasks %>       <td><%= task.name %></td>     <% end %>   </tr> <% end %> </table> 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -