2014-09-28 34 views
1

我正在使用Ruby On Rails的RXML爲Google創建站點地圖Feed。如何在ruby rxml中跳過分號

谷歌要求images are marked up with the image name space,需要有這樣中有一個分號的元素:如果我使用

xml.image:loc => "something" 

<image:image> 
    <image:loc>http://example.com/image.jpg</image:loc> 
</image:image> 

我得到

<image:image> 
    <image loc="something"/> 
</image:image> 

如果我使用

xml.image:loc("something") 

我得到

compile error 
/home/vagrant/website/app/views/feeds/sitemap.rxml:36: syntax error, unexpected '(', expecting kEND 
              xml.image:loc("something") 

如果我試試這個

xml.image:loc do 
    puts "something" 
end 

我得到這個

<image:image> 
    <image:loc> 
    </image:loc> 
</image:image> 
+0

我沒有足夠的權限才能添加RXML作爲標記。 – xiatica 2014-09-28 07:06:31

回答

3

RXML模板實際上builder

如果第一個參數神奇的標籤方法是一個符號,那麼這會使構建器使用方法名稱作爲名稱空間,將符號用作標記名稱。例如

xml.image(:loc, "something") 

會產生

<image:loc>something</image:loc> 

傳遞塊時也很理智:

xml.image(:image) do |xml| 
    xml.image(:loc, "http://example.com") 
end