Forum: Ruby on Rails AR to_xml problem with associations, Builder::XmlMarkup#to_a

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
161c0829c95d759f4dc0e0b71f712109?d=identicon&s=25 Rémi Gagnon (rgagnon)
on 2009-01-21 15:56
When I do a to_xml(with a block) on an association of a model I got a

Builder::XmlMarkup#to_ary should return Array

Example that does not work.

    @intervenant = Intervenant.find(params[:id])

    output = @intervenant.to_xml( :skip_types => false, :dasherize =>
false) do |xml|
      @intervenant.individu.to_xml( :builder => xml, :skip_instruct =>
true, :skip_types => false, :dasherize => false) do |xml_individu|

         #do special stuff at this level.....
      end
    end

Ex that do work but seems little bit dirty:


    @intervenant = Intervenant.find(params[:id])
    @individu = Individu.find(params[:id])

    output = @intervenant.to_xml( :skip_types => false, :dasherize =>
false) do |xml|
      @individu.to_xml( :builder => xml, :skip_instruct => true,
:skip_types => false, :dasherize => false) do |xml_individu|
         #do special stuff at this level.....
       end
      end

Any idea?
161c0829c95d759f4dc0e0b71f712109?d=identicon&s=25 Rémi Gagnon (rgagnon)
on 2009-01-21 16:20
Just to be more precise on my issue, it seems to happen only on
"has_one" relationship.  The "has_many" works like it should.

Rémi Gagnon wrote:
> When I do a to_xml(with a block) on an association of a model I got a
>
> Builder::XmlMarkup#to_ary should return Array
>
.....
This topic is locked and can not be replied to.