1

我有这个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 写这个?

4

1 回答 1

4

你可以each_slice用来做这样的事情:

.portlet-body
  - @products.each_slice(4) do |slice|
    .row-fluid
      - slice.each do |product|
        = render :partial => 'products/small', :locals => { :product => product}
于 2013-09-11T10:36:13.370 回答