rails渲染部分集合?

时间:2013-10-20 21:34:26

标签: ruby-on-rails ruby-on-rails-4

有没有更好的方法来渲染3行3而不专门调用按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>

1 个答案:

答案 0 :(得分:2)

您可以使用in_groups_of

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