ruby-on-rails – Ruby on Rails send_file在刷新页面之前不起作
发布时间:2020-12-16 20:51:57 所属栏目:百科 来源:网络整理
导读:我正在研究Rails服务器,我可以从中下载本地存储的电影和动漫等.这有点工作,但当我点击下载链接时,我必须刷新页面,以便下载实际开始. 这是处理下载的控制器: class DownloadController ApplicationController def index @title = params[:title] @name = par
我正在研究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 %> 编辑: 解决方法
你在使用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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |