This project is archived and is in readonly mode.

#2049 ✓wontfix
Joshua White

to_xml nil => true attribute should not appear when I skip types

Reported by Joshua White | February 23rd, 2009 @ 12:53 AM

When you run the to_xml method on a hash and an attribute contains no data or nil, rails, by default is rendering an attribute within the xml tah :nil => true.

I seems to me that this is inconsistent when I add the option :skip_types => true to add a 'type' tag that says nil.

The other thought is adding another options which says skip_nil_attribute or something.

For now I am just doing a gsub to remove it, but that seems wrong.

all = ExamRecord.all.to_xml(:include => [:patient], :skip_types => true)

....

person st
<date-of-birth>1134-11-11</date-of-birth> <demographic-notes>sfggsdfgs</demographic-notes> <first-name>Person</first-name> 82 <last-name>Personson</last-name> <middle-name>P</middle-name> bens123456 8989898989 <phone-evening>8988989898</phone-evening> 0 <social-security-number>123456789</social-security-number> * <zip-code nil="true"/> **

Comments and changes to this ticket

  • CancelProfileIsBroken
  • Dan Pickett

    Dan Pickett August 8th, 2009 @ 10:24 PM

    -1 verified that this occurs in 2-3-stable

    :skip_types is to remove data types while nil="true" indicates that the value is nil. The desired behavior does not match the means to do it. Perhaps passing a different option is better (:explicit_nils or something?)

    This would likely break a lot of legacy code, no?

  • Josh Nichols

    Josh Nichols August 10th, 2009 @ 04:00 AM

    I agree with Dan that skipping nils when you specify :skip_types seems to break the intention of it, which is to not include the type attribute with the class of the object. There'd also be the concern of backwards compatibility.

    I'd +1 an extra option for this though, ie :skip_nil_values

  • Hugo Peixoto

    Hugo Peixoto August 10th, 2009 @ 06:57 AM

    -1 for the requested behaviour for skip_types. I'm with both Dan and Josh on this one.

    I could add a skip_nil option to both activemodel and activesupport. Should I?

  • Derander

    Derander August 10th, 2009 @ 07:02 AM

    -1, verified behavior in 2-3-stable... I agree with Dan. I think that :skip_nils is a good idea Hugo, but it would probably be better as a new ticket.

  • Jeremy Kemper

    Jeremy Kemper August 10th, 2009 @ 07:06 AM

    • Assigned user cleared.
    • Tag cleared.
    • State changed from “new” to “wontfix”
    • Milestone cleared.
  • Joshua White

    Joshua White September 16th, 2009 @ 01:11 AM

    Does this mean that the ability to not include the nil=>'true' is left to the individual to do themselves? Should I submit a patch? I am for adding a skip_nils attribute as well.

  • bshand

    bshand January 27th, 2010 @ 11:49 AM

    Ticket #1480 already proposes a skip_nils attribute (including patches), but was rejected as invalid.

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>

Referenced by

Pages