Forum: Ruby on Rails REST: nested resources and rendering xml

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.
6c3acc025a63460a367b7981e606e032?d=identicon&s=25 Neubyr Neubyr (neubyr)
on 2009-04-02 08:49
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.
6c3acc025a63460a367b7981e606e032?d=identicon&s=25 Neubyr Neubyr (neubyr)
on 2009-04-03 04:37
Any help please...?

-
Thanks,
CS

Carlos Santana 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.
6c3acc025a63460a367b7981e606e032?d=identicon&s=25 Neubyr Neubyr (neubyr)
on 2009-04-03 06:03
http://api.rubyonrails.org/classes/ActiveRecord/Xm...
and comments posted on
http://afreshcup.com/2008/11/05/customizing-to_xml...
helped me out..

Thanks,
CS.


Carlos Santana wrote:
> Any help please...?
>
> -
> Thanks,
> CS
>
> Carlos Santana 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.
This topic is locked and can not be replied to.