# REST: nested resources and rendering xml

**URL:** <https://www.ruby-forum.com/t/rest-nested-resources-and-rendering-xml/164526>\
**Category:** Rails\
**Created:** [April 2, 2009, 8:49am UTC](https://www.ruby-forum.com/t/rest-nested-resources-and-rendering-xml/164526 "2009-04-02T08:49:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![neubyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@neubyr](https://www.ruby-forum.com/u/neubyr)\
**Post date:** [April 2, 2009, 8:49am UTC](https://www.ruby-forum.com/t/rest-nested-resources-and-rendering-xml/164526/1 "2009-04-02T08:49:31Z")

</div>

I am almost done with my RESTful application design.  
Following are the nested resources:  
map.resources :topics do |topics|  
topics.resources :items do |items|  
items.resources :attachments  
end  
end  
A topic has a list of items and items may have attachments.

When a user accesses particular topic, he/she should also see  
corresponding items and attachments. So a url topic\_path(1), i.e.,  
‘topic/1’ should also display related items and their attachments. This  
is not a problem while rendering page in a html/rhtml format. I am using  
\_item and \_attachment partials within topic/show.rhtml. How do I achieve  
this in case of xml? The usual ‘format.xml {render :xml =\>  
@topic.to\_xml}’ is of no use in this case.

Another way to access items and attachments would be:  
‘topic/:id/items’ and ‘topic/:id/items/:id/attachments’.  
This is pretty easy and rendering documents in different formats is not  
a problem here. This also suggests ‘Resource = Record’ relationship. Any  
thoughts on this?

One more thing I would like to add is downloading a topic in a zip file  
format. Isn’t it just another formatted url ‘format.zip { render :file  
=\> @topic.generate\_archive }’?

- 

Thanks,  
CS.

---

<div class="post-metadata">

**Author:** ![neubyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@neubyr](https://www.ruby-forum.com/u/neubyr)\
**Post date:** [April 3, 2009, 4:37am UTC](https://www.ruby-forum.com/t/rest-nested-resources-and-rendering-xml/164526/2 "2009-04-03T04:37:06Z")

</div>

Any help please…?

- 

Thanks,  
CS

Carlos S. wrote:

> I am almost done with my RESTful application design.  
> Following are the nested resources:  
> map.resources :topics do |topics|  
> topics.resources :items do |items|  
> items.resources :attachments  
> end  
> end  
> A topic has a list of items and items may have attachments.
> 
> When a user accesses particular topic, he/she should also see  
> corresponding items and attachments. So a url topic\_path(1), i.e.,  
> ‘topic/1’ should also display related items and their attachments. This  
> is not a problem while rendering page in a html/rhtml format. I am using  
> \_item and \_attachment partials within topic/show.rhtml. How do I achieve  
> this in case of xml? The usual ‘format.xml {render :xml =\>  
> @topic.to\_xml}’ is of no use in this case.
> 
> Another way to access items and attachments would be:  
> ‘topic/:id/items’ and ‘topic/:id/items/:id/attachments’.  
> This is pretty easy and rendering documents in different formats is not  
> a problem here. This also suggests ‘Resource = Record’ relationship. Any  
> thoughts on this?
> 
> One more thing I would like to add is downloading a topic in a zip file  
> format. Isn’t it just another formatted url ‘format.zip { render :file  
> =\> @topic.generate\_archive }’?
> 
> - 
> 
> Thanks,  
> CS.

---

<div class="post-metadata">

**Author:** ![neubyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@neubyr](https://www.ruby-forum.com/u/neubyr)\
**Post date:** [April 3, 2009, 6:03am UTC](https://www.ruby-forum.com/t/rest-nested-resources-and-rendering-xml/164526/3 "2009-04-03T06:03:34Z")

</div>

[http://api.rubyonrails.org/classes/ActiveRecord/XmlSerialization.html](http://api.rubyonrails.org/classes/ActiveRecord/XmlSerialization.html)  
and comments posted on  
[http://afreshcup.com/2008/11/05/customizing-to\_xml-and-to\_json-in-rails/](http://afreshcup.com/2008/11/05/customizing-to_xml-and-to_json-in-rails/)  
helped me out…

Thanks,  
CS.

Carlos S. wrote:

> Any help please…?
> 
> - 
> 
> Thanks,  
> CS
> 
> Carlos S. wrote:
> 
> > I am almost done with my RESTful application design.  
> > Following are the nested resources:  
> > map.resources :topics do |topics|  
> > topics.resources :items do |items|  
> > items.resources :attachments  
> > end  
> > end  
> > A topic has a list of items and items may have attachments.
> > 
> > When a user accesses particular topic, he/she should also see  
> > corresponding items and attachments. So a url topic\_path(1), i.e.,  
> > ‘topic/1’ should also display related items and their attachments. This  
> > is not a problem while rendering page in a html/rhtml format. I am using  
> > \_item and \_attachment partials within topic/show.rhtml. How do I achieve  
> > this in case of xml? The usual ‘format.xml {render :xml =\>  
> > @topic.to\_xml}’ is of no use in this case.
> > 
> > Another way to access items and attachments would be:  
> > ‘topic/:id/items’ and ‘topic/:id/items/:id/attachments’.  
> > This is pretty easy and rendering documents in different formats is not  
> > a problem here. This also suggests ‘Resource = Record’ relationship. Any  
> > thoughts on this?
> > 
> > One more thing I would like to add is downloading a topic in a zip file  
> > format. Isn’t it just another formatted url ‘format.zip { render :file  
> > =\> @topic.generate\_archive }’?
> > 
> > - 
> > 
> > Thanks,  
> > CS.
