Rails console - 在表格中显示活动记录结果
有没有办法在脚本/控制台环境中以表格格式显示 Active Record 结果?
Is there a way to display Active Record results in table format in the script/console environment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。有一个名为 hirb 的 gem 可以很好地做到这一点。
Yep. There's a gem called hirb that does this very well.
另请查看 http://tableprintgem.com。这是查看结构化数据列表的有效方法,可以轻松扫描和比较大量记录(对于许多人来说,这是对过去 SQL 命令行输出的舒适回归:)
table_print 最强大的功能是能够在与其相关的其他对象的上下文中查看数据。您可以使用访问嵌套对象所需的方法链来引用它们。此示例显示来自三个不同表的数据:
http://tableprintgem.com 有一个简短的介绍截屏视频
(全面披露:我写了这个 gem)
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 :)
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:
There's a short intro screencast at http://tableprintgem.com
(full disclosure: I wrote this gem)