public
Created

Security Article Part 3 - 11

  • Download Gist
data_helper.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
module DataHelper
# Expects a nested array such as:
# [[1,'Jez','iHiD'], [2,'Bob','<b>xyz</b>']]
#
# and outputs:
# <table>
# <tr><td>1</td><td>Jez</td><td>iHiD</td></tr>
# <tr><td>2</td><td>Bob</td><td>&lt;b&gt;xyz&lt;/b&gt;</td></tr>
# </table>
def data_to_table(data)
output = "<table>"
data.each do |row|
output << "<tr>"
row.each do |cell|
output << "<td>#{cell}</td>"
end
output = "</tr>"
end
output << "</table>"
output.html_safe
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.