views:

345

answers:

2

In Rails console: I was wondering if you could list/examine what databases/objects are available to you. Yes I know you can see using other tools, just curious if you can inspect them inside the Rails console. thanks.

A: 

Its a start, it can list:

models = Dir.new("#{RAILS_ROOT}/app/models").entries

Looking some more...

rtfminc
+4  A: 

You are probably seeking:

ActiveRecord::Base.connection.tables

and

ActiveRecord::Base.connection.table_structure("projects")

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

cwninja
Thanks, the first one works like I want. But the second one doesn't - hunted for something similar but no luck.
rtfminc
ActiveRecord::Base.connection.columns("foos") should also work, but it returns column objects, .map{|c| [c.name, c.type] } on the end fixes that.
cwninja
Thanks again, its what I wanted! Sooo much to learn. So better get back at it...
rtfminc