Retrieving Rails Model Column Names

前端 未结 2 1711
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-11 17:05

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

相关标签:
2条回答
  • 2021-02-11 17:51
    User.column_names
    

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

    0 讨论(0)
  • 2021-02-11 18:06

    Example:

    user = User.find(1)
    p user.attributes.keys
    
    0 讨论(0)
提交回复
热议问题