# AR to\_xml problem with associations, Builder::XmlMarkup#to\_a

**URL:** <https://www.ruby-forum.com/t/ar-to-xml-problem-with-associations-builder-xmlmarkup-to-a/158277>\
**Category:** Rails\
**Created:** [January 21, 2009, 3:56pm UTC](https://www.ruby-forum.com/t/ar-to-xml-problem-with-associations-builder-xmlmarkup-to-a/158277 "2009-01-21T15:56:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [January 21, 2009, 3:56pm UTC](https://www.ruby-forum.com/t/ar-to-xml-problem-with-associations-builder-xmlmarkup-to-a/158277/1 "2009-01-21T15:56:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [January 21, 2009, 4:20pm UTC](https://www.ruby-forum.com/t/ar-to-xml-problem-with-associations-builder-xmlmarkup-to-a/158277/2 "2009-01-21T16:20:29Z")

</div>

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

…
