From 5ca67eca21d2adfb418f96b63e7d3de237737a1e Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Sun, 15 May 2011 14:19:09 -0400 Subject: Add ActiveRecord::attribute_names to retrieve a list of attribute names. This method will also return an empty array on an abstract class or a model that the table doesn't exists. --- activerecord/lib/active_record/base.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index e1bf2ccc8a..cfe6d8d2de 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -767,6 +767,14 @@ module ActiveRecord #:nodoc: super || (table_exists? && column_names.include?(attribute.to_s.sub(/=$/, ''))) end + def attribute_names + @attribute_names ||= if !abstract_class? && table_exists? + column_names + else + [] + end + end + # Set the lookup ancestors for ActiveModel. def lookup_ancestors #:nodoc: klass = self -- cgit v1.2.3