I have the following code (simplified to get to the point):
- @assumptions[1].each do |ca|
- if count % 3 == 1
%tr
%th
= ca.value
- else
%th
= ca.value
- count = count + 1
I am not sure how to make this work in haml to have every 4 items create a new tag.
This is how it is outputting:
<tr>
<tr>
<th>
700.0
</th>
</tr>
<th>
1235.0
</th>
<th>
0.8
</th>
<th>
650.0
</th>
<tr>
<th>
1050.0
</th>
</tr>
<th>
0.2
</th>
</tr>
This is how I would like it to output:
<tr>
<th>
700.0
</th>
<th>
1235.0
</th>
<th>
0.8
</th>
</tr>
<tr>
<th>
650.0
</th>
<th>
1050.0
</th>
</tr>
I hope this makes sense.
You can use Enumerable's each_slice
method to group these into chunks of 3:
- @assumptions[1].each_slice(3) do |group|
%tr
- group.each do |ca|
%th= ca.value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With