[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?
Written by Valentino
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#