Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#3543

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

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

State: invalid
Milestone: none
Assigned to: Ryan Bigg Ryan Bigg
Importance: Low

Activity

  1. David Trasbo
    David Trasbo
    • 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.

    June 12th, 2010 @ 04:27 PM

  2. Santiago Pastorino
    Santiago Pastorino
    • 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

    June 18th, 2010 @ 04:01 PM