On 26 Feb 2009, at 10:37, MattFS218 wrote:
is it possible to get a quick example of how to override .to_xml?, and maybe add a little bit of markup?
THere's an example in the documentation for to_xml. Fred
On Feb 26, 5:16 pm, Frederick Cheung <[email protected]> wrote:On Feb 26, 10:08 am, MattFS218 <[email protected]> wrote:Hey Fred,Thanks for the rapid response.But when Iformat.fxml { render :fxml => @contacts.to_fxml(:methods=> [:my_action] ) }anddef my_action() return self.kvs.to_xml endthe resulting XML has the < and > symbols escaped out <?xml version="1.0"Oh I get you.Unless I'm mistaken, but associations are per Object, correct? Not perinstance. the Kvs i'm trying to output vary per instance. Any other recommendations?You can have interpolated conditions on an association (but this does rely on you being able to express your conditions in sql, prevents eager loading etc...). Another way is a custom to_xml method on your model, you'll get a Builder::XmlMarkup object given to you on which you can generate any xml you want Fred--mattOn Feb 26, 4:45 pm, Frederick Cheung <[email protected]> wrote:On Feb 26, 9:28 am, MattFS218 <[email protected]> wrote:I have a Contacts controller, that I'm using to output contacts when an index is called, but the XML that I will output for each contactvaries. I'm not having any success using :proc or :method:method could work, but the string my method returns, escapes the <>characters I'm using trying to "fake" XML mark-up.Basically, each contact has many Kvs, and I only want to :includeoutput some KV (not all) for each contact. I can :include kvs but that will include ALL. I cannot used proc, because there's no way for procto "know" which individual contact it's being run for.It seems like the easiest way would be a method that calls to_xml onthose kvs you want included. Not sure what you meant about fake xml mark-up in your comment above. Another way might be to :include an association whose conditions restrict it to those Kvs you are interested in.FredFredCan anyone recommend an easy way around this?--matt--~--~---------~--~----~------------~-------~--~----~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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
smime.p7s
Description: S/MIME cryptographic signature

