This project is archived and is in readonly mode.
record sensitive procs for to_xml
This adds support for an additional argument to procs passed
into to_xml via the :procs argument such that, if supplied, the
additional argument will be filled with the record being
An example that this solves: adding data conventionally within
the scope of the controller (urls, for example) to an xml-formatted
series of ActiveRecord models. Possible alternatives to using
record-sensitive procs include creating url-generating methods in
the model and referencing them in to_xml's :methods -- a violation
of MVC -- and writing a builder template -- a chore, considering
to_xml gets you 99% there.
A longer description of what this solves appears here: http://stackoverflow.com/questio...
Comments and changes to this ticket
Looks like you did it by the book; did you try asking for feedback from the community at large? I just stumbled across the page at stackoverflow and found my way here.
From the contrib guide:
Once you have a patch and a lighthouse ticket you need to find some people to give you feedback. You can either email the core list or ask in #rails-contrib on irc.freenode.net
Thanks for pointing that part of the contribution guide out. I posted to the Rails core group: http://groups.google.com/group/rubyonrails-core/t/d5276f6ecc6359cf?...
Hopefully it will catch someone's eye now :)
Remove the ternary operator, it just obfuscates things:
if proc.arity == 1
proc.call ... else
proc.call ... end
Also update the docs so that it explains why you might want to do this, 9 times out of 10 you're better off overriding .to_xml in your object, but this 'include a url' case is a good reason not to.
Thanks for the feedback, Koz :) I've implemented your suggestions and revised the patch, which is now attached. The implementation of AR's XML Serialization has moved into ActiveModel, so I moved my patch there. I also added unit tests for the :procs option in ActiveModel.
- State changed from new to resolved
(from [c39151a84768397d3bb025c6e8f877eac59ebbf9]) Patch to ActiveModel's (and ActiveRecord, by association) XML serialization: If two parameters are present in Procs supplied to to_xml's :procs option, the model being serialized will be passed as the second argument [#2373 state:resolved]
Signed-off-by: Joshua Peek firstname.lastname@example.org
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>