将<div>添加到“每个块”,每个2个结果使用rails 3 </div>

时间:2012-06-26 19:32:03

标签: ruby-on-rails

我的每个块都有:

<% for f in @following %>
 <div class="span6">
  <%= f.name %>
 </div>
<% end %>

html结果:

<div class="span6"> John</div>
<div class="span6"> kevin</div>
<div class="span6"> Peter</div>
<div class="span6"> Andrew</div>
.
.
.

我想添加一个<div class="row"></div>,每个结果类似于:

<div class="row">
 <div class="span6"> John</div>
 <div class="span6"> kevin</div>
</div>
<div class="row">
 <div class="span6"> Peter</div>
 <div class="span6"> Andrew</div>
</div>

我希望每行显示2个结果。我该怎么办?

1 个答案:

答案 0 :(得分:8)

结帐each_slice

<% @following.each_slice(2) do |followers| %>
  <div class="row">
    <% followers.each do |f| %>
      <div class="span6">
        <%= f.name %>
      </div>
    <% end %>
  </div>
<% end %>