Method: ActiveRecord::AttributeMethods::ClassMethods#attribute_names
- Defined in:
- lib/active_record/attribute_methods.rb
#attribute_names ⇒ Object
Returns an array of column names as strings if it’s not an abstract class and table exists. Otherwise it returns an empty array.
class Person < ActiveRecord::Base
end
Person.attribute_names
# => ["id", "created_at", "updated_at", "name", "age"]
236 237 238 239 240 241 242 |
# File 'lib/active_record/attribute_methods.rb', line 236 def attribute_names @attribute_names ||= if !abstract_class? && table_exists? attribute_types.keys else [] end.freeze end |