我有这个erb文件:
<div class="portlet-body">
<% @products.each_with_index do |product, idx| %>
<% if (idx % 4) == 0 and idx > 0 %>
</div>
<% end %>
<% if (idx % 4) == 0 %>
<div class="row-fluid">
<% end %>
<%= render :partial => 'products/small', :locals => { :product => product} %>
<% end %>
</div>
我怎样才能在HAML中写这个?
答案 0 :(得分:4)
您可以使用each_slice
执行以下操作:
.portlet-body
- @products.each_slice(4) do |slice|
.row-fluid
- slice.each do |product|
= render :partial => 'products/small', :locals => { :product => product}