查看文章 |
如何让Rails直接输出XML或Xhtml格式的文件
2009-01-22 17:29
Rails默认的输出是html格式,即使输出的数据是XML格式的数据,因为Response的ContentType被设置为text/html,所以也无法在firefox下正常浏览;
解决这个问题的办法就是安装 Rails Plugin: xhtml_content_type 的插件
1 ruby script/plugin install http://svn.codahale.com/xhtml_content_type
2 修改需要输出XML的controller方法,在render 后面增加参数:content_type => :xml
这样,再通过Firebug去看response的contentType就是"XML charset=utf-8"
具体内容看http://blog.codahale.com/2006/05/23/rails-plugin-xhtml_content_type/ |
最近读者: