Hyphenated XML tags in Builder October 13, 2008
Posted by John Dewey in ActiveRecord, Example, Rails, Ruby.trackback
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
I like that trick
As you should, it was your “tricky trick”!
or just…
xml.tag! “hyphenated-tag-name”, “data”