【发布时间】:2016-03-16 20:55:34
【问题描述】:
我想为我的数组中的每个值循环下载一个文件。
我的班级有两种方法:
def test
testarray = ['value1', 'value2', 'value3']
testarray.each do |value|
download_file(value)
end
end
def download_file(value)
send_file("public/downloads/test/" + value +".pdf", :filename => value + ".pdf", :type => "application/pdf", :diposition => "inline")
end
但是当我调用我的测试方法时,只下载了数组的最后一个元素。控制台打印以下内容:
Sent file public/downloads/shapefiles/test1.pdf (0.1ms)
Sent file public/downloads/shapefiles/test2.pdf (0.1ms)
Sent file public/downloads/shapefiles/test3.pdf (0.1ms)
Completed 200 OK in 2ms (ActiveRecord: 0.0ms)
但我的浏览器只下载最后一个文件,在本例中为test3.pdf。
【问题讨论】: