Permalink
Browse files

Fix the AR::Base#inspect method [closes #1294]

  • Loading branch information...
1 parent bf159aa commit b2db8740eabbb9b9c6afb237530d33ef7fc807e9 @franckverrot franckverrot committed May 25, 2011
Showing with 10 additions and 6 deletions.
  1. +10 −6 activerecord/lib/active_record/base.rb
@@ -1870,12 +1870,16 @@ def readonly!
# Returns the contents of the record as a nicely formatted string.
def inspect
- attributes_as_nice_string = self.class.column_names.collect { |name|
- if has_attribute?(name)
- "#{name}: #{attribute_for_inspect(name)}"
- end
- }.compact.join(", ")
- "#<#{self.class} #{attributes_as_nice_string}>"
+ inspection = if @attributes
+ self.class.column_names.collect { |name|
+ if has_attribute?(name)
+ "#{name}: #{attribute_for_inspect(name)}"
+ end
+ }.compact.join(", ")
+ else
+ "not initialized"
+ end
+ "#<#{self.class} #{inspection}>"
end
protected

0 comments on commit b2db874

Please sign in to comment.