ruby - Rails each loop insert tag every 6 items? -


I have the number of x image objects that i need a loop in a scene and every 6 objects have a new device Either you want to create (for a gallery).

I have seen the cycle but it is changing every other record. Does anyone know one way to insert code in one view every 6 times?

I could have done this with the nested loop, but I'm a little stumped on this.

To avoid inline computation, you with # ish Enumerable # each_slice can use every_slice in this case breaks the array in N segment.

  & lt;% @ images.each_slice (6) do Slices | -% & gt; & Lt; Div class = "gallery" & gt; & Lt;% slice.each do | Picture | -% & gt; & Lt;% = image_tag (image.url, alt = & gt; image.alt)% & gt; & Lt;% end -% & gt; & Lt; / Div & gt; & Lt;% end -% & gt;  

Comments