This project is archived and is in readonly mode.

#3543 ✓invalid
Pascal

Array#to_xml doesn't pick up the root tag name like ActiveRecord#to_xml does

Reported by Pascal | December 5th, 2009 @ 10:55 PM

Hi,

This is not a bug but more a orthogonality discrepancy.

Looking at the code in Array#to_xml shows that the root tag is generated with (stripped):
ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(first.class.name))

It should be something like this to be more consistant with ActiveRecord#to_xml:
first.class.model_name.plural

This leverage the use of #model_name which takes care for us for those inflections.

Regards,

Pascal

Comments and changes to this ticket

  • David Trasbo

    David Trasbo June 12th, 2010 @ 04:27 PM

    • Assigned user set to “Ryan Bigg”

    The reason why Array#to_xml uses the generic name on the class of the first item in the array, is that the method should be able to convert any array to XML, not just an array of Active Record objects.

    That said, you could ask the first item's class if it responds to model_name, and just use name if it doesn't. Patch welcomed. For now this ticket can be marked incomplete.

  • Santiago Pastorino

    Santiago Pastorino June 18th, 2010 @ 04:01 PM

    • State changed from “new” to “invalid”

    I don't know if you're talking about Rails 2-3 or master but as David said Array#to_xml is generic so we can't use model_name

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>

Tags

Pages