markjm markjm - 1 year ago 123
HTML Question

Ruby/Rails/HTML/HAML - create a two column table with first column cells spanning dynamic number of rows

I am trying to create an HTML table in HAML that has a first column where each cell spans a dynamic number of rows based on the number of values in an Array which will be split across multiple cells in the second column. So for example, if Array.size == 2, then the first cell in the first column will have rowspan=2 and the second column will have Array[0] in the first row and Array[1] in the second row and the column 1 value will span both rows. The HAML code I wrote to do this is as follows:

- @array1.each do |item|
%td{:rowspan => "#{item.array.size}"}= time_tag(item.created_at)
- item.array.each do |item|
%td= "#{}"

The issue I am having is that HAML automatically inserts one set of row tags after each loop through the second block which results in the second ending up in the first column of the second row instead of in the second column of the second row. How can I fix my code to make the table work as I described it?

Answer Source

I don't know if I understand you but I think it could work with the following code:

- @products.each do |item|
    %td{:rowspan => "#{item.array.size}"}= "#{}"
      - item.array.each do |item2|
          %td= "#{}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download