This project is archived and is in readonly mode.
Array#to_xml accepts :root_attrs
Reported by Ernesto Jiménez | November 7th, 2008 @ 06:50 PM | in 2.x
You can define root attributes using :root_attrs option:
@projects.to_xml(:root_attrs => {:page => 1, :per_page => 3}) <?xml version="1.0" encoding="UTF-8"?> <projects page="1" per_page="3" type="array"> <project> <name>project 1</name> </project> <project> <name>project 2</name> </project> <project> <name>project 3</name> </project> </projects>
This is useful for paginated XMLs
Comments and changes to this ticket
-
Juanjo Bazán November 8th, 2008 @ 11:26 AM
- Tag set to verified
Nice addition. Works for me and docs look good.
-
DHH November 9th, 2008 @ 06:28 PM
- State changed from new to wontfix
The problem is that there won't parity with Hash.from_xml, which is the sister method of to_xml. If you give it your sample string, you'll get {"projects"=>[{"name"=>"project 1"}, {"name"=>"project 2"}, {"name"=>"project 3"}]} back -- in other words, the attributes are just dropped.
Until we find a way of dealing with that, I don't see this as a good fit.
-
Ernesto Jiménez November 10th, 2008 @ 01:27 AM
It actually seems that the problem is with the type="array".
omitting type="array" gets the parameters.
A possible solution might be avoiding type="array" when :root_attrs is set?
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>