def index
@downloads = get_all_downloads
end
def get_all_downloads
return SfDownload.where(is_active: true)
end
def download
require 'zip'
require 'open-uri'
if get_all_downloads
zipfile_name = "SfDocuments.zip"
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
get_all_downloads.each do |sfd|
# Two arguments:
# - The name of the file as it will appear in the archive
# - The original file, including the path to find it
zipfile.add(File.basename(sfd.sf_url), open(sfd.sf_url))
end
end
end
end
SfDownload 中保存了网络 url, 我想做个页面,将选中的 Url 打包,然后点击下载按钮保存到电脑里,如何实现呢?