Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a core issue with Rails. What's happening is that when Instruments are being included, an <code>instrument_id</code> attribute is getting added. Then, when each Instrument is serialized, the XmlSerializer class determines the type of that attribute based on the Instrument class' definition, using the type attribute for each column. Since the <code>instrument_id</code> attribute does not exist in the class definition, a nil object is returned which, as of Ruby 1.9, does not have a <code>type</code> attribute, which Rails is depending on.</p> <p><em>(I don't think the patch in the thread you linked to works -- but the one I've provided below does.)</em></p> <p>There are two ways to fix this:</p> <ol> <li> Don't serialize <code>instrument_id</code> (good idea). <pre><code>render :xml => @musicians.to_xml( :include => { :instruments => { :except => :instrument_id } } )</code></pre> </li> <li>Or patch Rails core (bad idea). <pre><code>--- a/activerecord/lib/active_record/serializers/xml_serializer.rb 2011-04-20 15:01:10.000000000 -0700 +++ b/activerecord/lib/active_record/serializers/xml_serializer.rb 2011-04-20 15:00:42.000000000 -0700 @@ -226,8 +226,10 @@ class Attribute &lt; ActiveModel::Serializers::Xml::Serializer::Attribute #:nodoc: def compute_type + Rails.logger.info("key: #{name}, hash: #{@serializable.class.columns_hash[name]}") type = @serializable.class.serialized_attributes.has_key?(name) ? - super : @serializable.class.columns_hash[name].type + super : @serializable.class.columns_hash[name].nil? ? + NilClass : @serializable.class.columns_hash[name].type case type when :text</code></pre> </li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload