This project is archived and is in readonly mode.

#5811 ✓stale
Claudio Poli

to_xml should convert Hash returning methods in :methods

Reported by Claudio Poli | October 15th, 2010 @ 04:18 AM

currently when using :methods on to_xml if the called method returns a Hash Rails won't convert it, instead it just display a string with the hash content.

A workaround it to use :procs to convert manually the offending method to to_xml with a bunch of options:

options[:procs] ||= []
options[:procs] << { |options| cover_urls.to_xml(options.update(:root => 'cover-urls'))}

I realize that since it is Hash people would want to customize it, but I think we can provide some default behaviour, like the example above (automatically set the root to method_name.dasherize).

The as_json/to_json are perfectly fine in rendering a method that returns a Hash, if we can get to_xml to behave the same we can DRY up a lot of code and share it between the as_json and to_xml overrides in AR models.

Comments and changes to this ticket

  • Claudio Poli

    Claudio Poli October 15th, 2010 @ 04:19 AM

    • Title changed from “to_xml should conver Hash in :methods if found” to “to_xml should convert Hash returning methods in :methods”
  • Ryan Bigg

    Ryan Bigg October 19th, 2010 @ 08:32 AM

    • Tag cleared.
    • Importance changed from “” to “Low”

    Automatic cleanup of spam.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:47 PM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:47 PM

    • State changed from “open” to “stale”

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=""></a>