I have two models: ledger and label. A ledger can contain many
labels.
Here is the xml returned from http://localhost/ledgers/78.xml:
<ledger>
<account-id type="integer">11</account-id>
<amount type="decimal">30.0</amount>
<check-number/>
<created-on type="date">2007-10-22</created-on>
<date type="date">2007-10-22</date>
<description>Deposit</description>
<id type="integer">78</id>
</ledger>
Question:
How can I return the labels associated with the ledger? The xml should
look like this (notice the "labels" addition):
<ledger>
<account-id type="integer">11</account-id>
<amount type="decimal">30.0</amount>
<check-number/>
<created-on type="date">2007-10-22</created-on>
<date type="date">2007-10-22</date>
<description>Deposit</description>
<id type="integer">78</id>
<labels>
<label>Food</label>
<label>Music</label>
</labels>
</ledger>
--~--~---------~--~----~------------~-------~--~----~
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 just figured it out.
Instead of this: format.xml { render :xml => @ledger.to_xml }
do this: format.xml { render :xml => @ledger.to_xml(:include =>
[ :labels ]) }
Works like a charm. :)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
FYI I found the answer here: http://api.rubyonrails.org/classes/ActiveRecord/XmlSerialization.html#M000910 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---