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.

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

#2049

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"/> **

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

State: wontfix
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. CancelProfileIsBroken
  2. Dan Pickett
    Dan Pickett

    -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?

    August 8th, 2009 @ 10:24 PM

  3. Josh Nichols
    Josh Nichols

    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

    August 10th, 2009 @ 04:00 AM

  4. Hugo Peixoto
    Hugo Peixoto

    -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?

    August 10th, 2009 @ 06:57 AM

  5. Derander
    Derander

    -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.

    August 10th, 2009 @ 07:02 AM

  6. Jeremy Kemper
    Jeremy Kemper
    • Assigned user cleared.
    • Tag cleared.
    • State changed from new to wontfix
    • Milestone cleared.

    August 10th, 2009 @ 07:06 AM

  7. Joshua White
    Joshua White

    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.

    September 16th, 2009 @ 01:11 AM

  8. bshand
    bshand

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

    January 27th, 2010 @ 11:49 AM