Ruby on rails 从url地址导入CSV并导出为XML--Rails
两个问题:Ruby on rails 从url地址导入CSV并导出为XML--Rails,ruby-on-rails,xml,csv,import,export,Ruby On Rails,Xml,Csv,Import,Export,两个问题: 如果没有表单,如何从web地址导入文件 示例:organization.import(:from=>“”) 如何使用XMLBuilder而不从数据库中提取数据 更多信息 我的公司将wufoo用于web表单。来自wufoo的数据将导出为csv文件。要将数据输入我公司的cms,需要将其格式化为xml。除了csv文件的url之外,我不需要存储任何数据。我认为这可以作为一个简单的rails应用程序使用 使用openuri()获取文件,使用ruby的csv库解析文件。或者,使用漂亮且简单的cs
require 'rio'
require 'fastercsv'
url = 'http://remote-url.com/file.csv'
people = FasterCSV.parse(rio(url).read)
xml = ''
1.upto(people.size-1) do |row_idx|
xml << " <record>\n"
people[0].each_with_index do |column, col_idx|
xml << " <#{column.parameterize}>#{people[row_idx][col_idx]}</#{column.parameterize}>\n"
end
xml << " </record>\n"
end
require'rio'
需要'fastercsv'
url='1〕http://remote-url.com/file.csv'
people=FasterCSV.parse(rio(url.read)
xml=“”
1.最多(人。尺寸-1)do| row|U idx|
xml