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
2010-01-20 00:24:32
+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
2010-01-20 02:29:59
Thanks, the first one works like I want. But the second one doesn't - hunted for something similar but no luck.
rtfminc
2010-01-20 08:36:16
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
2010-01-20 10:15:15
Thanks again, its what I wanted! Sooo much to learn. So better get back at it...
rtfminc
2010-01-20 21:39:46