ruby-on-railsconsole

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


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.


Solution

  • 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.