34

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

mbm
  • 1,902
  • 2
  • 19
  • 28

2 Answers2

64
User.column_names

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

Gregory Mostizky
  • 7,231
  • 1
  • 26
  • 29
6

Example:

user = User.find(1)
p user.attributes.keys
Zabba
  • 64,285
  • 47
  • 179
  • 207