Moussa Sarr Moussa Sarr - 2 months ago 7
CSS Question

How do I display three images in a row given that I am using bootstrap?

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|
<div class="row_thumbnails">
# In row 1 I want 3 entries(images displayed in thumbnail look)
</div>

<%end%>

Answer

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 %>
Comments