I’m using will_paginate to paginate my items eight at a time.
I want to organize them in a table with two rows and four columns while still maintaining pagination. How can I do this?
So far I have:
<%= will_paginate @items, :page_links => false %>
<table id="item_table">
<tr>
<% for item in @items %>
<td>Test</td>
<% end %>
</tr>
</table>
But I need to change this somehow that I can have @items be a temporary array of every four items, instead of eight. Here’s the ideal output:
<-- 1 2 ... 5 6 -->
Test Test Test Test
Test Test Test Test
Where obviously the top links lead to the next eight items. Any ideas?
Update
each_slice is an enumerable itself so there is not need to create an array before calling each on it, I reduced the code by a line
<% @item.each_slice(4) do |item_new| %>
<% item_new.each do |item|%>
<%= item.name %>
<% end %>
<% end %>
The code is just a snippet from one of my app, implementing almost the same thing you are trying to achieve, I hope it does help, don’t forget to include the will_paginate and complete the table. This is just some logic you would require.