From 813e8ba93bf099dd065512f958a516c6b893a841 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 11 Jun 2007 05:02:42 +0000 Subject: Fix Base#inspect when not every attribute is present. Closes #8623. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6995 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index e1f3dce7ce..8c7b83f82a 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1852,7 +1852,6 @@ module ActiveRecord #:nodoc: # Format attributes nicely for inspect. def attribute_for_inspect(attr_name) - raise "Attribute not present #{attr_name}" unless has_attribute?(attr_name) || new_record? value = read_attribute(attr_name) if value.is_a?(String) && value.length > 50 @@ -1947,8 +1946,10 @@ module ActiveRecord #:nodoc: # Nice pretty inspect. def inspect attributes_as_nice_string = self.class.column_names.collect { |name| - "#{name}: #{attribute_for_inspect(name)}" - }.join(", ") + if has_attribute?(name) || new_record? + "#{name}: #{attribute_for_inspect(name)}" + end + }.compact.join(", ") "#<#{self.class} #{attributes_as_nice_string}>" end -- cgit v1.2.3