下载文件而不离开页面 - rails

时间:2015-09-20 11:14:54

标签: ruby-on-rails file download google-drive-realtime-api

我正在尝试使用谷歌驱动器作为源来获取下载链接。

目前,我可以通过将其下载到临时文件,打开新页面然后在新页面上下载文件来使其工作。

用户控制器

def download_file
  .....
  file = <get the file>
  file.download_to_file(Rails.root.join("tmp/#{file.title}"))
  send_data Rails.root.join("tmp/#{file.title}"),
    :type=>file.available_content_types.first,
    filename:file.title, :x_sendfile=>true
end

查看

%td
 = link_to "Download", download_file_path(@user), target: "_blank"

目前,这会打开一个新页面(发出一些错误的哔哔声),然后给我一个文件。

是否有更优雅的方式(如果可能,没有js)

从同一页面下载它们都无法下载文件。 (尝试了redirect_to:返回发送回来和远程:true但都失败了。)

0 个答案:

没有答案
相关问题