Last Updated: February 25, 2016
·
455
· codenamev

[rails] Display objects in groups

Do you have a list of images you want to display two-per-div? three-per-div?

Discovered the each_slice method:

in a view (HAML), this will show two images per div

image_list = [file1, file2, file3, file4, file5]

- image_list.each_slice(2) do |image1, image2|
  = image_tag image1
  = image_tag image2 if image2.present?