This project is archived and is in readonly mode.
record sensitive procs for to_xml
Reported by greenagain | March 30th, 2009 @ 01:41 AM | in 3.0.2
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
serialized.
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
-
ppowpow May 27th, 2009 @ 10:51 PM
This would be awesome, and could actually make procs useful for serialization of arrays of AR objects. Why, O why is this patch sitting in here and not getting any love?
-
greenagain May 28th, 2009 @ 08:35 PM
Appreciate the support, ppowpow. I think that this would be extraordinarily useful too, especially for so tiny a change. I tried to tag and categorize the ticket properly. Does it seem like I filed it wrong or something?
-
ppowpow May 28th, 2009 @ 10:39 PM
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
-
greenagain June 2nd, 2009 @ 02:38 PM
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 :)
-
Michael Koziarski July 12th, 2009 @ 04:24 AM
Remove the ternary operator, it just obfuscates things:
if proc.arity == 1
proc.call ... else
proc.call ... endAlso 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.
-
greenagain July 15th, 2009 @ 04:46 AM
- no changes were found...
-
greenagain July 15th, 2009 @ 04:50 AM
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.
-
Michael Koziarski July 15th, 2009 @ 05:10 AM
- Milestone cleared.
- Assigned user set to josh
Josh is the active model guy
-
Repository July 23rd, 2009 @ 03:18 AM
- 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 josh@joshpeek.com
http://github.com/rails/rails/commit/c39151a84768397d3bb025c6e8f877... -
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to
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>
People watching this ticket
Attachments
Referenced by
- 2373 record sensitive procs for to_xml (from [c39151a84768397d3bb025c6e8f877eac59ebbf9]) Patch t...