当each_with_index
循环中的索引可以被4整除时,我想创建一个新的表行。即 - 我想要每行4个单元格。
当我尝试执行以下操作时,我得到undefined method %
错误。
<% @brand_promotions.each_with_index do |index, brand_promotion| %>
<% if (index % 4) == 0 %>
<div class="row">
<% end %>
<div class="col-3">
Column <%= index %>
</div>
<% if (index % 4) == 0 %>
</div>
<% end %>
<% end %>
我该如何实现这一目标?
index
是第二个参数
<% @brand_promotions.each_with_index do |brand_promotion, index| %>