I have an image model and each image has related entries, which are also images. I want to display the related three entries in a row depending on how many of them there are. I am using bootstrap.
This is what I have written so far:
<% @image.related_entries.each.in_groups_of(3, false).each_with_index do |entry_row, i|
# In row 1 I want 3 entries(images displayed in thumbnail look)
Try using each_slice
<% @image.related_entries.each_slice(3) do |related_img_slice| <div class="row"> <% related_img_slice.each do |related_img| <div class="col-md-4"> <%= image_tag(related_img.location) %> </div> <% end %> </div> <% end %>