我不知道最好的做法是什么,但在我的情况下,我在模型中做1,2,和3一类的方法。我会创建一个模型方法,它接受基本XML文件的名称。
所以我会做这样的事情...(警告:我不是100%确定这是语法正确的,我有点新的Rails仍然)
# app/models/mymodel.rb
class MyModel < ActiveRecord::Base
# ...
def self.formatXml(xml_base)
dataRecords = MyModel.find(:whatever) # step 1
# open the XML and read it into a string, this is step 2
# take the XML string, do the appropriate gsubs
return my_xml_string;
end
end
# app/controllers/mycontroller.rb
class MyController < ActionController::Base
# ...
def myAction
formattedXml = MyModel.formatXml(whateverXmlFileName)
render :text => formattedXml
end
end
由于这看起来好 – user448157 2010-09-23 15:50:40