How to get an array with column names of a table

前端 未结 3 1320
时光取名叫无心
时光取名叫无心 2021-01-31 14:59

I need an array with the column names of a table

Any ideas how I can do this with rails 3.0.0rc?

3条回答
  •  日久生厌
    2021-01-31 15:37

    For ActiveRecord:

    Model.column_names
    

    For Mongoid:

    Model.attribute_names
    

    Output:

    => ["id", "title", "body", "created_at", "updated_at"] 
    

    Note: It'll be _id instead of id for Mongoid

提交回复
热议问题