I know of the find_in_batches
method for ActiveRecord, but this doesn't allow me to set my :order
or :limit
.
I am trying to loop through my data, and for every 6 items I want to wrap them in a <div
>.
I was trying to whole...
<%
i = 0
@media.each do |media|
%>
<% if i%6 %><div class="section"><% end %>
[...]
<% if i%6 %></div><% end %>
<%
i += 1
end
%>
But I feel this isn't efficient the "Rails" way. Could I possibly split up my array into 4 different arrays of 6? I am trying to find the best approach to this and was hoping you guys could help.
In the end I need it to come out something like this:
<!--
I have 24 items in my array, and I need to wrap every 6 inside a div.
-->
<div class="section">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<div class="section">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<div class="section">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<div class="section">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
Thanks in advance!