我似乎无法让这个工作.我想从不同的Web服务器中提取CSV文件以读取我的应用程序.这就是我想要的方式:
url = 'http://www.testing.com/test.csv' records = FasterCSV.read(url, :headers => true, :header_converters => :symbol)
但这不起作用.我试过谷歌搜索,我想出的就是这个摘录:实用的红宝石宝石
所以,我尝试修改如下:
require 'open-uri' url = 'http://www.testing.com/test.csv' csv_url = open(url) records = FasterCSV.read(csv_url, :headers => true, :header_converters => :symbol)
...我得到一个can't convert Tempfile into String
错误(来自FasterCSV宝石).
谁能告诉我如何使这项工作?
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 http://fastercsv.rubyforge.org/