I am reading RESTful Web Services, where it is advised as a good practice to connect resources. Is there a way to include article urls in @articles.to_xml ? -- fxn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
As far as I know, simple ways to do it are (from the Rdoc documentation): - Including any methods on the object(s) being called, using :methods: firm.to_xml :methods => [ :calculated_earnings, :real_earnings ] <firm> # ... normal attributes <calculated-earnings>100000000000000000</calculated-earnings> <real-earnings>5</real-earnings> </firm> - Calling any Procs on the object(s), uinge :procs. The Procs are passed a modified version of the options hash that was given to to_xml. proc = Proc.new { |options| options[:builder].tag!(''abc'', ''def'') } firm.to_xml :procs => [ proc ] <firm> # ... normal attributes as shown above ... <abc>def</abc> </firm> Xavier Noria wrote:> I am reading RESTful Web Services, where it is advised as a good > practice to connect resources. > > Is there a way to include article urls in @articles.to_xml ? > > -- fxn-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 10, 2008, at 6:21 PM, Damaris Fuentes wrote:> As far as I know, simple ways to do it are (from the Rdoc > documentation): > - Including any methods on the object(s) being called, using :methods: > > firm.to_xml :methods => [ :calculated_earnings, :real_earnings ] > <firm> > # ... normal attributes > <calculated-earnings>100000000000000000</calculated-earnings> > <real-earnings>5</real-earnings> > </firm> > - Calling any Proc‘s on the object(s), uinge :procs. The Proc‘s are > passed a modified version of the options hash that was given to > to_xml. > > proc = Proc.new { |options| options[:builder].tag!(''abc'', ''def'') } > firm.to_xml :procs => [ proc ] > <firm> > # ... normal attributes as shown above ... > <abc>def</abc> > </firm>Thank you! I wondered though whether there was a builtin way in AR::Base#to_xml to generate something like this: <articles> <article ref="http://www.example.com/articles/567"> <code>AGH877</code> <price>234.45</price> </article> ... </article> AFAIK you have to code that customization yourself. (Of course a model does not know it has a URL so that''s fine.) -- fxn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ah, yes, I have right now this same problem. I''m afraid the only way to do it is creating your own RXML template :( -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I wondered though whether there was a builtin way in AR::Base#to_xml > to generate something like this: > > <articles> > <article ref="http://www.example.com/articles/567"> > <code>AGH877</code> > <price>234.45</price> > </article> > ... > </article>standard rails restful stuff uses a predictable URL scheme, so this isn''t really needed. Also, routing uses the current request context, and that''d have to be passed into #to_xml somehow. You could do that now using the :procs option. -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---