Hyphenated XML tags in Builder October 13, 2008Posted by John Dewey in ActiveRecord, Example, Rails, Ruby.
I typically use to_xml when building a shallow representation of my model in XML. It becomes hella difficult to maintain the format of my XML when nesting numerous levels deep. Sometimes you gotta use a Builder.
If you would like your tags to be hyphenated (like the to_xml default), here is a nice trick:
xml.__send__('hyphenated-tag-name'.to_sym) do xml.tag "data" end