Skip to content

Instantly share code, notes, and snippets.

@tka
Last active December 20, 2015 03:29
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 tka/6064129 to your computer and use it in GitHub Desktop.
Save tka/6064129 to your computer and use it in GitHub Desktop.
rails dump db schema to html table
ActiveRecord::Base.connection.tables.map{|table|
x=ActiveRecord::Base.connection.select('show full columns from '+table);
x.columns.slice!(7);
x.rows.each{|r| r.slice!(7)};
"<h1>#{table}</h1>"+'<table class="table table-bordered table-striped"><tr><th>'+x.columns.join('</th><th>')+"</th><th></th></tr>\n" + x.rows.map{|y| '<tr><td>'+y.join('</td><td>')+"</td><td></td></tr>\n"}.join('')+"</table>\n"}.join('</hr>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment