LoginSignup
70
47

More than 5 years have passed since last update.

ActiveRecordを使ってRails consoleからテーブル一覧がほしい

Last updated at Posted at 2016-03-25
ActiveRecord::Base.connection.execute('show tables').map{|a| p a.first}

僕は開発中Rails consoleから移動せずにやりたい思っているので、
あれ、こんなテーブルあったっけ見たいな時に
ActiveRecordを使ってRails consoleからテーブル一覧がほしかった

executeでshow tablesを実行して、すると入れ子になってテーブル名が返ってくるので、mapして取り出す

。。。と思ったら、
投稿してすぐ気づいた。

これでいけた

ActiveRecord::Base.connection.tables

さすがActiveRecordさん。。。

70
47
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
70
47