Moussa Sarr Moussa Sarr - 1 year ago 84
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)


Answer Source

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) %>
    <% end %>
<% end %>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download