Retrieving Rails Model Column Names

前端 未结 2 1144
一生所求
一生所求 2021-02-11 17:02

When one retrieves a Rails model object, how are the column (or object attribute) names accessed?

相关标签:
2条回答
  • 2021-02-11 17:46

    Example:

    user = User.find(1)
    p user.attributes.keys
    
    0 讨论(0)
  • 2021-02-11 18:02
    User.column_names
    

    Like a lot of things in Rails, it just works :)

    0 讨论(0)
提交回复
热议问题