# Article urls in @articles.to\_xml

**URL:** <https://www.ruby-forum.com/t/article-urls-in-articles-to-xml/115534>\
**Category:** Rails\
**Created:** [September 26, 2007, 1:07am UTC](https://www.ruby-forum.com/t/article-urls-in-articles-to-xml/115534 "2007-09-26T01:07:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [September 26, 2007, 1:07am UTC](https://www.ruby-forum.com/t/article-urls-in-articles-to-xml/115534/1 "2007-09-26T01:07:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [January 11, 2008, 12:16am UTC](https://www.ruby-forum.com/t/article-urls-in-articles-to-xml/115534/2 "2008-01-11T00:16:22Z")

</div>

On Jan 10, 2008, at 6:21 PM, Damaris F. wrote:

> - 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]
> 
> # … normal attributes as shown above …
> 
> def

Thank you!

I wondered though whether there was a builtin way in AR::Base#to\_xml  
to generate something like this:

`AGH877` 234.45 ...

AFAIK you have to code that customization yourself. (Of course a model  
does not know it has a URL so that’s fine.)

– fxn

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [January 10, 2008, 6:21pm UTC](https://www.ruby-forum.com/t/article-urls-in-articles-to-xml/115534/3 "2008-01-10T18:21:31Z")

</div>

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:

- 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.

Xavier N. 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

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [January 11, 2008, 5:13am UTC](https://www.ruby-forum.com/t/article-urls-in-articles-to-xml/115534/4 "2008-01-11T05:13:31Z")

</div>

> I wondered though whether there was a builtin way in AR::Base#to\_xml  
> to generate something like this:
> 
> `AGH877` 234.45 ...

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 O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [January 11, 2008, 12:43am UTC](https://www.ruby-forum.com/t/article-urls-in-articles-to-xml/115534/5 "2008-01-11T00:43:59Z")

</div>

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