内容简介:翻译自:https://stackoverflow.com/questions/4509023/how-to-save-ruby-builder-generated-xml-instead-of-rendering-it-in-rails-applicat
我有一个构建器,在调用create时呈现xml.如何跳过渲染步骤,但将xml保存到文件系统?
def create
@server = Server.new(params[:server])
respond_to do |format|
if @server.save
flash[:notice] = "Successfully created server."
format.xml
else
render :action => 'new'
end
end
end
XML构建器可以将其数据写入支持<<<
xml = Builder::XmlMarkup.new # Uses the default string target
# TODO: Add your tags
xml_data = xml.target! # Returns the implictly created string target object
file = File.new("my_xml_data_file.xml", "wb")
file.write(xml_data)
file.close
但由于File类支持<
操作符>
file = File.new("my_xml_data_file.xml", "wb")
xml = Builder::XmlMarkup.new target: file
# TODO: Add your tags
file.close
有关详细信息,请查看 the documentation of XmlMarkup .
运算符也是如此>翻译自:https://stackoverflow.com/questions/4509023/how-to-save-ruby-builder-generated-xml-instead-of-rendering-it-in-rails-applicat
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Android应用程序生成以太坊钱包
- Android里应用程序,应用程序窗口和视图对象之间的关系
- 使用 Bluemix、Watson Discovery 和 Cloudant 构建移动应用程序来分析其他应用程序
- ChromeOS 终端应用程序暗示其即将支持 Linux 应用
- 这几天在C程序中有哪些应用程序?
- Zookeeper详解-应用程序(七)
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Algorithms Unlocked
Thomas H. Cormen / The MIT Press / 2013-3-1 / USD 25.00
Have you ever wondered how your GPS can find the fastest way to your destination, selecting one route from seemingly countless possibilities in mere seconds? How your credit card account number is pro......一起来看看 《Algorithms Unlocked》 这本书的介绍吧!