411 REFERENCE · Wikibooks
Ruby on Rails/ActionView/Builder
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
XmlBuilder is a class which supports creating XML output with Ruby methods. Most method calls sent to the XmlBuilder class will be rendered directly. You also have access to all instance variables defined in the action. For example:
In /app/controllers/demo_controller.rb:
class DemoController < ApplicationController
def index
@title = 'History'
end
end
In /app/views/demo/index.rxml:
<nowiki>
xm.instruct! # <?xml version="1.0" encoding="UTF-8"?>
xm.html { # <html>
xm.head { # <head>
xm.title(@title) # <title>History</title>
} # </head>
xm.body { # <body>
xm.comment! "HI" # <!-- HI -->
xm.h1("Header") # <h1>Header</h1>
xm.p("paragraph") # <p>paragraph</p>
} # </body>
} # </html>
</nowiki>