Rails: rendering XML adds tag

前端 未结 2 769
有刺的猬
有刺的猬 2021-02-13 16:02

I\'ve got a Rails controller which is going to output a hash in XML format - for example:

class MyController < ApplicationController
  # GET /example.xml
  de         


        
2条回答
  •  感情败类
    2021-02-13 16:28

    I think if you're converting an object to XML, you need a tag which wraps everything, but you can customise the tag name for the wrapper:

    def index        
      @output = {"a" => "b"}
    
      respond_to do |format|
        format.xml  {render :xml => @output.to_xml(:root => 'output')}
      end
    end
    

    Which will result in:

    
      
        b
      
    
    

提交回复
热议问题