Reputation: 8330
Say that I have a data model called Widget
. If I pick one widget...
widget = Widget.find(1)
... then I can get its attributes with widget.attributes.keys
.
But what if I don't want to find a Widget?
Is there a way to list all the attributes of the Widget class (which inherits from ActiveRecord::Base
) without having to retrieve one particular Widget first?
Upvotes: 2
Views: 3658
Reputation: 10796
If you need "accessible attributes", meaning attributes marked as accessible with attr_accessible
, then you can use Widget.accessible_attributes
.
Upvotes: 1
Reputation: 21791
You can get attributes directly from data model:
Widget.column_names
Upvotes: 6