<div class="container">
<div class="row">
<%= render @buildings %>
</div>
</div>
如何在两列中呈现上述内容?
<div class="row">
<div class="col-md-6">1st column</div>
<div class="col-md-6">2nd column</div>
</div>
最好是水平顺序,即
1,2,3,4
成为
1,2
3,4
_building.html.erb
<% building.image %>
答案 0 :(得分:6)
你可以试试这个:
<div class="container">
<% @buildings.each_slice(2) do |(b1, b2)| %>
<div class="row">
<div class="col-md-6"><%= render b1 %></div>
<div class="col-md-6"><%= render b2 if b2 %></div>
</div>
<% end %>
</div>