# Format.xml not rendering associated model properly

**URL:** <https://www.ruby-forum.com/t/format-xml-not-rendering-associated-model-properly/149555>\
**Category:** Rails\
**Created:** [September 26, 2008, 6:21am UTC](https://www.ruby-forum.com/t/format-xml-not-rendering-associated-model-properly/149555 "2008-09-26T06:21:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [September 26, 2008, 6:21am UTC](https://www.ruby-forum.com/t/format-xml-not-rendering-associated-model-properly/149555/1 "2008-09-26T06:21:41Z")

</div>

respond\_to do |format|  
format.html # index.html.erb  
format.xml { render :xml =\> @directories }  
end

#Software:0xb7046548

The model directory belongs to a software instance.

–  
Anthony E.  
408-656-2473  
[http://anthony.ettinger.name](http://anthony.ettinger.name)

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [September 26, 2008, 6:21pm UTC](https://www.ruby-forum.com/t/format-xml-not-rendering-associated-model-properly/149555/2 "2008-09-26T18:21:59Z")

</div>

What magic were you expecting to have happen? (Rails did exactly what  
you told it to).

Don’t you want something like

format.xml { render :xml =\> @software.to\_xml( :include =\> :directories )  
}

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [September 26, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/format-xml-not-rendering-associated-model-properly/149555/3 "2008-09-26T18:27:45Z")

</div>

If you want only @directories, then you should create an rxml template  
to be used under software, where you marshall the xml data is any old  
format you want.

for directory in @directories  
xml.directory do  
xml.directory\_name(directory.name)  
etc  
etc  
end  
end

---

<div class="post-metadata">

**Author:** ![chovy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecd19e/32.png) [@chovy](https://www.ruby-forum.com/u/chovy)\
**Post date:** [September 26, 2008, 11:28pm UTC](https://www.ruby-forum.com/t/format-xml-not-rendering-associated-model-properly/149555/4 "2008-09-26T23:28:35Z")

</div>

On Sep 26, 9:27 am, Ar Chron [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## end
> 
> Posted viahttp://www.ruby-forum.com/.

I want each directory as xml, just how it is…but the associated  
“software” object, I want to include that. What you wrote initially  
looks backwards to me.

since this is requested as directories.xml

 .... \<%= directory.software.name %\>

It sounds like that’s the only way to create an index.rxml file?

I figured there would be an automatic way to map associated models to  
the default xml output.
