instance method
attribute_names
Ruby on Rails 7.1.6
Since v3.2.22.5Signature
attribute_names()
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"]
Source
# File activerecord/lib/active_record/attribute_methods.rb, line 242
def attribute_names
@attribute_names ||= if !abstract_class? && table_exists?
attribute_types.keys
else
[]
end.freeze
end
Defined in activerecord/lib/active_record/attribute_methods.rb line 242
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::AttributeMethods::ClassMethods