Say I want to call .each on @users and in my erb I have:
<% @user.each do |user| %>
<p><%= user.name %></p>
<% end %>
Simple enough. But after every 5th user I need to add a clearfix of this:
<div class="clearfix visible-xs"></div>
What is the best way to go about this?
Enumerable#each_with_index should be ok:
<% @users.each_with_index do |user, index| %>
<p><%= user.name %></p>
<% if (index + 1) % 5 == 0 %>
<div class="clearfix visible-xs"></div>
<% end %>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With