views:

103

answers:

2

I'm trying to get the output of the query 'SHOW TABLES FROM database_name' into an array using the ActiveRecord database connection. I can't seem to figure out how to do this. can someone please enlighten me?

-C

+3  A: 

I tried

ActiveRecord::Base.connection.execute("DESCRIBE TABLE table_name")

and was told to check my SQL manual. Doing so, I found that

ActiveRecord::Base.connection.execute("DESCRIBE table_name").each{|r| p r }

worked. Put whatever actual logic you need in the block.

Ben Hughes
I was almost there, I just wasn't using the block. Thanks alot!-C
Chris Drappier
+3  A: 

Use what ActiveRecord gives you out of the box:

ActiveRecord::Base.connection.tables
François Beausoleil
haha, wow. how did i miss that?
Chris Drappier