Permalink
Browse files

to_xml doesn't work in such case: Event.select('title as t').to_xml [#…

…4840 state:resolved]

NilClass.type is no longer defined in Ruby 1.9 and causes ActiveRecord::Base.to_xml to fail with message: undefined method `type' for nil:NilClass
  • Loading branch information...
knoopx authored and tenderlove committed Sep 30, 2010
1 parent c594f22 commit fe0db2b80588446b34f5f89bbe73f04b88fb06c9
Showing with 8 additions and 2 deletions.
  1. +8 −2 activerecord/lib/active_record/serializers/xml_serializer.rb
@@ -226,8 +226,14 @@ def add_associations(association, records, opts)
class Attribute < ActiveModel::Serializers::Xml::Serializer::Attribute #:nodoc:
def compute_type
- type = @serializable.class.serialized_attributes.has_key?(name) ?
- super : @serializable.class.columns_hash[name].type
+ case
+ when @serializable.class.serialized_attributes.has_key?(name)
+ type = super
+ when @serializable.class.columns_hash.has_key?(name)
+ type = @serializable.class.columns_hash[name].type
+ else
+ type = NilClass
+ end
case type
when :text

0 comments on commit fe0db2b

Please sign in to comment.