Blair Anderson
Blair Anderson

Reputation: 20181

rails render partial collection?

Is there a better way to render 3 rows of 3 without calling specifically to the items grouped by 3?

<div class="row">
  <%= render partial: 'thumbnail', collection: @pages[0..2] %>
</div>

<div class="row">
  <%= render partial: 'thumbnail', collection: @pages[3..5] %>
</div>

<div class="row">
  <%= render partial: 'thumbnail', collection: @pages[6..8] %>
</div>

Upvotes: 1

Views: 380

Answers (1)

Ryan Bigg
Ryan Bigg

Reputation: 107738

You can use in_groups_of for this:

<% @pages.in_groups_of(3) do |group| %>
  <%= render partial: 'thumbnail', collection: group %>
<% end %>

Upvotes: 2

Related Questions