class MyController < ApplicationController # GET /example.xml def index @output = {"a" => "b"} respond_to do |format| format.xml {render :xml => @output} end end end
但是,Rails添加了< hash>标签,我不想要,即:
<hash> <a> b </a> </hash>
我该如何输出呢?
<a> b </a>
def index @output = {"a" => "b"} respond_to do |format| format.xml {render :xml => @output.to_xml(:root => 'output')} end end
这将导致:
<output> <a> b </a> </output>