I’m trying to display a series of pictures in a table. Rather than just
house each of the pictures in separate rows, I’d like to have 5 pictures
per
row. So, basically after I iterate through five columns in my table, I
need
to start a new row and show the next 5 pictures.
Could someone help me with the looping structure I’d need to create to
do
this?
Thank you!
Sarah
Hello Sarah,
I’m trying to display a series of pictures in a table. Rather than just
house each of the pictures in separate rows, I’d like to have 5 pictures per
row. So, basically after I iterate through five columns in my table, I need
to start a new row and show the next 5 pictures.
Could someone help me with the looping structure I’d need to create to do
this?
Have a look at Array#in_groups_of
(defined in ActiveSupport). It perfectly fits to your need.
Example of the doc :
%w(1 2 3 4 5 6 7).in_groups_of(3) {|g| p g}
gives :
[“1”, “2”, “3”]
[“4”, “5”, “6”]
[“7”, nil, nil]
-- Jean-François.