Rails: How to list database tables/objects using the Rails console?

rtfminc picture rtfminc · Jan 20, 2010 · Viewed 126.2k times · Source

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.

Answer

cwninja picture cwninja · Jan 20, 2010

You are probably seeking:

ActiveRecord::Base.connection.tables

and

ActiveRecord::Base.connection.columns('projects').map(&:name)

You should probably wrap them in shorter syntax inside your .irbrc.