3
votes

Say I have 16 objects in my collection, I want to create 4 rows of 4 each.

How do I do that using partials?

One way is to just use one partial on the main page, and have that partial render each row. Then inside that partial, have it 4 objects - but how do I actually do that such that it doesn't repeat objects and all this good stuff?

So the structure I am thinking is a partial (that produces 4 rows) and in each partial is another partial that produces 4 objects side by side.

But not quite sure how to pull that off.

Suggestions?

1

1 Answers

6
votes
<% @objects.in_groups_of(4, false) do |objects| %>
  <div class="row">
    <% objects.each do |object| %>
      <%= render object %>
    <% end %>
  </div>
<% end %>