gpt4 book ai didi

ruby-on-rails - 将
添加到 "each block"每 2 个结果与 rails 3

转载 作者:行者123 更新时间:2023-12-03 16:00:27 24 4
gpt4 key购买 nike

我有一个类似的每个块:

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

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

最佳答案

结帐 each_slice

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

关于ruby-on-rails - 将 <div> 添加到 "each block"每 2 个结果与 rails 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11214665/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com