大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – Ruby on Rails send_file在刷新页面之前不起作用?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是处理下载的控制器:
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秒.
你知道导致这种延迟的原因吗?
<%= 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
以上是大佬教程为你收集整理的ruby-on-rails – Ruby on Rails send_file在刷新页面之前不起作用?全部内容,希望文章能够帮你解决ruby-on-rails – Ruby on Rails send_file在刷新页面之前不起作用?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。