Skip to content

Instantly share code, notes, and snippets.

@iHiD
Created June 25, 2012 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iHiD/2990648 to your computer and use it in GitHub Desktop.
Save iHiD/2990648 to your computer and use it in GitHub Desktop.
Security Article Part 3 - 11
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment