31

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

mbm
  • 1,842
  • 2
  • 19
  • 27

2 Answers2

59
User.column_names

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

Gregory Mostizky
  • 7,161
  • 1
  • 24
  • 29
5

Example:

user = User.find(1)
p user.attributes.keys
Zabba
  • 62,418
  • 46
  • 175
  • 205