Rails:如何使用Rails控制台列出数据库表/对象? [英] Rails: How to list database tables/objects using the Rails console?
本文介绍了Rails:如何使用Rails控制台列出数据库表/对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道您是否可以列出/检查Rails控制台中可用的数据库/对象。我知道您可以使用其他工具来查看它们,我很好奇。
谢谢。
I was wondering if you could list/examine what databases/objects are available to you in the Rails console. I know you can see them using other tools, I am just curious. Thanks.
推荐答案
您可能正在寻求:
ActiveRecord::Base.connection.tables
和
ActiveRecord::Base.connection.columns('projects').map(&:name)
您应该在 .irbrc
内用较短的语法包装它们。
You should probably wrap them in shorter syntax inside your .irbrc
.
这篇关于Rails:如何使用Rails控制台列出数据库表/对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文