2014-09-28 135 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