我的每个块都有:
<% 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个结果。我该怎么办?
答案 0 :(得分:8)
<% @following.each_slice(2) do |followers| %>
<div class="row">
<% followers.each do |f| %>
<div class="span6">
<%= f.name %>
</div>
<% end %>
</div>
<% end %>