如何在Ruby on Rails中读取远程文件的内容?

在这里我的文件: http : //example.com/test.txt

我必须阅读http://example.com/test.txt (一个JSON字符串)的内容并在Ruby中解析它

我建议使用open-uri :

require 'json' require 'open-uri' result = JSON.parse open('http://example.com/data.json').read 
 require 'net/http' uri = URI('http://my.json.emitter/some/action') json = Net::HTTP.get(uri) 

json将包含您从uri获取的JSON字符串。

然后阅读此 StackOverflowpost。