ruby on rails - Extra <to_s/> when using builder to generate XML -


i'm trying generate kml using builder. know options out there doing 2.2 specific things aren't supported kml gems i've looked @ , able accomplish leveraging xml framework.

i tag @ end of file when rendering kml/xml. suspect i'm missing basic setting builder object or how i'm rendering output it. here's simple example demonstrates issue:

def kml2dot2   @site = site.find(params[:id])   xml = builder::xmlmarkup.new(:indent => 2)   xml.instruct!   xml.kml("xmlns" => "http://www.opengis.net/kml/2.2") {     xml.placemark       xml.name @site.mapnamefull       xml.point         xml.coordinates @site.lat.to_s + "," + @site.lng.to_s + ",0"       end     end   }   render :text => xml, :type=>"text/kml"  end  

produces:

<?xml version="1.0" encoding="utf-8"?> <kml xmlns="http://www.opengis.net/kml/2.2">   <placemark>     <name>seattle city hall</name>     <point>       <coordinates>47.6040746,-122.33005,0</coordinates>     </point>   </placemark> </kml> <to_s/> 

i'm trying understand how avoid <to_s/> being included , i'm doing wrong builder. insight.

you don't need initialize xml builder object. use integrated builder template handler.

  1. call template kml2dot2.xml.builder
  2. write code directly in view

example

def kml2dot2   @site = site.find(params[:id]) end  # kml2dot2.xml.builder xml.kml("xmlns" => "http:// www.opengis.net/kml/2.2")   xml.placemark     xml.name @site.mapnamefull     xml.point        xml.coordinates "#{@site.lat},#{@site.lng},0"     end   end end 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -