ruby-on-rails – Ruby on Rails send_file在刷新页面之前不起作用?

我正在研究Rails服务器,我可以从中下载本地存储的电影和动漫等.这有点工作,但当我点击下载链接时,我必须刷新页面,以便下载实际开始.

这是处理下载的控制器:

class DownloadController < ApplicationController
  def index
    @title = params[:title]
    @name = params[:name]
    @path = '/media/sf_Anime,_VN,_LN/Watching,not watched yet/'+@title+'/'+@name
    send_file( @path )
  end
end

这是链接到该控制器的链接

<% @episodes.each do |x| %>
<p> <%= x %><%= link_to " Download",{controller: 'download',action: 'index',title: @title,name: x } %> </p>
<% end %>

编辑:
我今天做了一些测试,并注意到如果我尝试发送较小的文件(文本或图像),下载链接会立即生效.我还注意到下载链接实际上适用于电影,但下载开始需要20-30秒.
你知道导致这种延迟的原因吗?

解决方法

你在使用turbolinks吗? Turbolinks显然不能与send_file( https://github.com/rails/turbolinks/issues/182)很好地配合.尝试在link_to帮助器中添加“data:{no-turbolink:true}”(或“’data-no-turbolink’=> true”),例如:
<%= link_to "Downloadable File",downloadable_file,data: { no-turbolink: true } %>

另见:Rails 4,asset pipeline causes user downloadable files to be downloaded twice,rails won’t send_data as file,Ruby on Rails send_file,code in controller action running twice

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...