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

后端 未结 6 1781
忘了有多久
忘了有多久 2020-12-02 04:30

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

6条回答
  •  情书的邮戳
    2020-12-02 04:42

    To get a list of all model classes, you can use ActiveRecord::Base.subclasses e.g.

    ActiveRecord::Base.subclasses.map { |cl| cl.name }
    ActiveRecord::Base.subclasses.find { |cl| cl.name == "Foo" }
    

提交回复
热议问题