检索Rails模型列名称

当检索Rails模型对象时,如何访问列(或对象属性)名称?

User.column_names 

像Rails中的很多东西一样,它只是工作:)

例:

 user = User.find(1) p user.attributes.keys