ActiveRecord: List columns in table from console

前端 未结 8 1355
遥遥无期
遥遥无期 2020-12-22 23:21

I know that you can ask ActiveRecord to list tables in console using:

ActiveRecord::Base.connection.tables

Is there a command that would li

8条回答
  •  猫巷女王i
    2020-12-22 23:59

    Using rails three you can just type the model name:

    > User
    gives:
    User(id: integer, name: string, email: string, etc...)
    

    In rails four, you need to establish a connection first:

    irb(main):001:0> User
    => User (call 'User.connection' to establish a connection)
    irb(main):002:0> User.connection; nil #call nil to stop repl spitting out the connection object (long)
    => nil
    irb(main):003:0> User
    User(id: integer, name: string, email: string, etc...)
    

提交回复
热议问题