rails console - display active record results in a table
Asked Answered
P

2

29

Is there a way to display Active Record results in table format in the script/console environment?

Phototherapy answered 29/9, 2010 at 23:30 Comment(0)
P
38

Yep. There's a gem called hirb that does this very well.

Portrait answered 29/9, 2010 at 23:34 Comment(1)
Thanks, that did the trick! Sorry but I can't vote your answer because I don't have enough reputation.Phototherapy
G
11

Also check out http://tableprintgem.com. It's an efficient way to view a list of structured data, making it easy to scan and compare across large swaths of records (and for many people, it's a comfortable return to the SQL command line output of yesteryear :)

table_print ruby gem - explore your data

The most powerful feature of table_print is the ability to see your data in the context of other objects it relates to. You can reference nested objects with the method chain required to reach them. This example is showing data from three different tables:

  • name from the Author table (reached through author.name)
  • title from the Book table (reached through author.books.title)
  • caption from the Photo table (reached through author.books.photos.caption)

table_print ruby gem - contextualize your data

There's a short intro screencast at http://tableprintgem.com

(full disclosure: I wrote this gem)

Gallic answered 5/11, 2013 at 21:32 Comment(3)
Couldn't you do the last thing with normal SQL queries, or the the rails method chain, to get such printouts with other table gems like hirb?Ham
I'm a big fan, but you should disclose that this is your gem.Redintegration
oh yeah, thanks. I know it's mine, sometimes I forget other people aren't in my head :)Gallic

© 2022 - 2024 — McMap. All rights reserved.