article urls in @articles.to_xml

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

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>

Xavier Noria wrote:

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&quot;&gt;      <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

Ah, yes, I have right now this same problem. I'm afraid the only way to do it is creating your own RXML template :frowning:

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&quot;&gt;      <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.