0

I need show a list of products in a carousel using bootstrap grouped by 4 elements in each 'item' class.

here is my develop

<div class="carousel-inner" role="listbox">
  <% products.each_with_index do |product, n| %>

    <% if n % 4 == 0 %>
      <div class="item <%= 'active' if n == 0 %>">
    <% end %>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        ...
      </div>
    <% if n % 4 != 0 %>
      </div>
    <% end %>

  <%end%>
</div>

the problem is when i try close 'item' class. I can't catch the opposite of multiples of 4.

Joaquin Diaz
  • 184
  • 1
  • 5
  • 16

1 Answers1

0
<div class="carousel-inner" role="listbox">
  <% products.each_slice(4).with_index do |slice, index| %>
    <div class="item <%= 'active' if index == 0 %>">
    <% slice.each do |product| %>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        ...
      </div>
    <% end %>
    </div>
  <% end %>
</div>
Alex
  • 16