Reputation: 2563
Below is my loop I am running in a rails helper method.
part_child_option.each do |o|
html += "<div class='col-sm-2 uno_part_wrapper'>"
html += "<label class = 'p_name' for='#{attr_name}'>"
html += image_tag o.photo(:small), class: "tick_option_img",
html += "</label>"
html += "</div>"
end
html.html_safe
end
I have a problem now. class col-sm-2
is there, so It is under a class row
in my view. The row is outside of my helper and hence I am not able to loop it.
The pointed solution doesn't have such scenario
Now I want my row
class to close once the col-sm-2
is done with six times. And then I want to start the class row
again and everything same as above in my class row.
I hope the question is clear now.
How can this be done.
Upvotes: 0
Views: 85
Reputation: 660
you are asking same question that already asked. please have a look Here
user each_slice
to make chunks of 6 of your array then iterate each loop.
e.g
array.each_slice(6) do |chunk|
chunk.each do |o|
end
end
in your case
rows = ""
part_child_option.each_slice(6) do | six_o |
row = "<div class='row'>"
six_o.each do | o |
row += "your logic"
end
row += "</div>"
rows += row
end
Upvotes: 2