Search code examples
htmlruby-on-railshtml-tablehamlcustom-data-attribute

Dynamic table with data attributes


I have a dynamically created table with the row and column numbers stored as data attributes in each cell:

%table
  - (1..3).each do |row|
    %tr
      - (1..3).each do |column|
        %td.cell{:data => {:x => column, :y => row}}

The HTML this generates is fine, except that whenever the column equals the row, data-y is missing:

<table>
  <tr>
    <td data-x='1'></td>
    <td data-x='2' data-y='1'></td>
    <td data-x='3' data-y='1'></td>
  </tr>
  <tr>
    <td data-x='1' data-y='2'></td>
    <td data-x='2'></td>
    <td data-x='3' data-y='2'></td>
  </tr>
  <tr>
    <td data-x='1' data-y='3'></td>
    <td data-x='2' data-y='3'></td>
    <td data-x='3'></td>
  </tr>
</table>

Anyone know what's causing this?


Solution

  • This is a bug in Haml version 4.0.0. It’s fixed in 4.0.1.rc.1 – the fix hasn’t made it into a full release as of writing this but you should be okay with the rc1 gem.