ruby-on-rails – FasterCSV:读取远程CSV文件
发布时间:2020-12-17 01:23:51 所属栏目:百科 来源:网络整理
导读:我似乎无法让这个工作.我想从不同的Web服务器中提取CSV文件以读取我的应用程序.这就是我想要的方式: url = 'http://www.testing.com/test.csv'records = FasterCSV.read(url,:headers = true,:header_converters = :symbol) 但这不起作用.我试过谷歌搜索,我
我似乎无法让这个工作.我想从不同的Web服务器中提取CSV文件以读取我的应用程序.这就是我想要的方式:
url = 'http://www.testing.com/test.csv' records = FasterCSV.read(url,:headers => true,:header_converters => :symbol) 但这不起作用.我试过谷歌搜索,我想出的就是这个摘录:Practical Ruby Gems 所以,我尝试修改如下: require 'open-uri' url = 'http://www.testing.com/test.csv' csv_url = open(url) records = FasterCSV.read(csv_url,:header_converters => :symbol) …而且我得到一个无法将Tempfile转换为String错误(来自FasterCSV gem). 谁能告诉我如何使这项工作? 解决方法require 'open-uri' url = 'http://www.testing.com/test.csv' open(url) do |f| f.each_line do |line| FasterCSV.parse(line) do |row| # Your code here end end end http://www.ruby-doc.org/core/classes/OpenURI.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |