The real beauty comes into play when things get a little more complicated
defprepare @users = ["Jonas","Pascal","Chris"] @numbers = ["One","Two","Three"] @numeros = ["Uno","Dos","Tres"]end# ...table class: "foo"do tr class: "bar"do @users.each do|user| th text: userendend tr do @numbers.each do|number| td text: numberendend tr do @numeros.each do|numero| td text: numeroendend# you are still in pure Ruby, so feel free to do other stuff as well tr do td do plain "Do"end td text: "Custom" td do plain "Stuff"endendend
thead, tbody and tfoot are optional containers for any number of trs. If none are specified, tbody will be used to contain all tr components. thead is typically used for the head of the table, and tfoot for any table footer, where applicable, such as a sum or count.
table do thead do tr do th text: "Product" th text: "Price"endend# tbody is unnecessary, since it has no class or id and will be added automatically# tbody do tr do td text: "Apples" td text: "3.50"end tr do td text: "Oranges" td text: "2.75"end tr do td text: "Bananas" td text: "4.99"end# end tfoot do tr do td text: "Total:" td text: "11.24"endendend