4

我有一个每个块,例如:

<% 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>每 2 个结果,例如:

<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 个结果。我该怎么做?

4

1 回答 1

9

出 each_slice

<% @following.each_slice(2) do |followers| %>
  <div class="row">
    <% followers.each do |f| %>
      <div class="span6">
        <%= f.name %>
      </div>
    <% end %>
  </div>
<% end %>
于 2012-06-26T19:39:07.187 回答