Created
January 26, 2017 10:37
-
-
Save akostadinov/c984116ed3db525d1b58dffedc44bab1 to your computer and use it in GitHub Desktop.
Building XML under Rails 5.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'builder' | |
# See more about syntax on | |
# http://api.rubyonrails.org/classes/ActionView/Base.html | |
# https://github.com/jimweirich/builder | |
# http://builder.rubyforge.org/ | |
xml = +"" | |
builder = Builder::XmlMarkup.new(target: xml, indent: 2) | |
builder.rootelementname { |x| | |
x.properties { | |
x.property(name: "some-root-element-property", value: "some value 1") | |
x.property(name: "some-other-root-element-property", value: "some value 2") | |
} | |
x.subelement(someprop: "somevalue") { | |
x.tag!("tag-with-dashes", prop: "value X") | |
} | |
} | |
puts xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment