On 5 Nov 2008, at 02:49, RubyNewbie wrote:
>
> Our Rails application needs to support both xml and json formats. In
> some cases, we need to return custom XML that spans several objects
> and associations. I've been able to write custom to_xml methods that
> use the builder and block functionality. When trying the same thing
> with the to_json method, I failed to get the same result.
>
> Basically to_xml has this signature: to_xml(options = {}, &block).
> I've perused around and it appears to_json has this signature:
> to_json(options = {}). Is there a version of to_json that will yield
> to a block
> and provide the json builder? Can someone please tell me if I've done
> something wrong with the code below? Is there is a plugin or newer
> version of Rails that will add the same support for to_json that
> to_xml supports?
I don't believe there is a json builder - it's just not how the json
stuff in rails works. basically there's an obvious implementation of
to_json for hashes and arrays, everything else just hangs off that (so
to_json on an activerecord object basically takes the hash of
attributes (module except/only etc... options) and calls to_json on it)
Fred
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---