# Rendering XML from the result of a find

**URL:** <https://www.ruby-forum.com/t/rendering-xml-from-the-result-of-a-find/70987>\
**Category:** Rails\
**Created:** [October 4, 2006, 4:09pm UTC](https://www.ruby-forum.com/t/rendering-xml-from-the-result-of-a-find/70987 "2006-10-04T16:09:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [October 4, 2006, 4:09pm UTC](https://www.ruby-forum.com/t/rendering-xml-from-the-result-of-a-find/70987/1 "2006-10-04T16:09:27Z")

</div>

Hi,

I am quite new to Rails.

I have a model, store with  
belongs\_to :owner

in my controller I have

@store = Store.find(199, :include =\> :owner)  
render :xml @store.to\_xml

The result is that the xml only contains the store data, not the owners  
data, even though it has retrieved the owners data along with the store.

How can I get the owner data to be included in the XML.

Is it possible to get just specific fields into the XML, such as  
owner.name

Thanks

Andrew

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [October 4, 2006, 5:40pm UTC](https://www.ruby-forum.com/t/rendering-xml-from-the-result-of-a-find/70987/2 "2006-10-04T17:40:47Z")

</div>

You should see this page:

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000934)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

To include owners data: @store.to\_xml(:include =\> “owner”)  
To show only specific field, use :only or :except options.

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [October 4, 2006, 6:22pm UTC](https://www.ruby-forum.com/t/rendering-xml-from-the-result-of-a-find/70987/3 "2006-10-04T18:22:53Z")

</div>

I tried it out with the include. It wasn’t giving me the results I  
wanted, so I will try to use Builder Templates and do my own XML.

Using render gives the owner data in a child node under a store. What I  
wanted was to have the nodes, such as owner.name at the same level as  
the store.

Andrew

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [October 4, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/rendering-xml-from-the-result-of-a-find/70987/4 "2006-10-04T18:59:58Z")

</div>

I take back what I said, about not having the correct format. I found a  
way to access the nested xml values, so I don’t need to use builder.

Andrew
