我的应用程序目录中有一个名为“uploads”的文件夹,用户可以在其中上传和下载文件。我不希望上传文件夹位于公共目录中,因为我想控制下载授权。
在我的控制器中,我有:
send_file Rails.root.join('app', 'uploads', filename), :type => 'application/zip', :disposition => 'inline', :x_sendfile=>true
这实际上很好用。问题在于,当我在生产服务器上运行rake assets:precompile,并且有一个assets目录时,文件会下载两次。第一次下载文件时,浏览器似乎什么也没发生(没有加载旋转),但是我在Google Chrome Web开发人员网络选项卡中看到数据正在传输。然后,在文件被下载后,会弹出提示询问用户是否要下载该文件。
从public目录中删除assets文件夹可以解决此问题,但我想使用asset pipeline。我还尝试将asset pipeline requires从require_tree更改为require_directory。
有人知道如何使send_file与asset pipeline正常工作吗?
谢谢。
visit = function(url) { if (browserSupportsPushState && browserIsntBuggy) { cacheCurrentPage(); reflectNewUrl(url); return fetchReplacement(url); } else { return document.location.href = url; } };
这会导致文件被下载两次。现在的问题是...如何禁用一个方法的turbolinks? - MichaelHajuddah'data-no-turbolink' => true
传递给link_to
助手以防止 Turbolinks 干扰下载。 - MichaelHajuddah