我最近将我的应用程序升级到 Rails 5,但我的下载停止工作。当我单击下载按钮时,浏览器挂起,没有任何 react 。
class DownloadsController < ApplicationController
def download
send_file(
"#{Rails.root}/public/file.rtf",
filename: "file.rtf",
type: :rtf,
disposition: "attachment"
)
end
end
我有 rtf mimetype
Mime::Type.register "text/richtext", :rtf
日志显示一切正常
Sent file /home/deploy/app/releases/20160518213049/public/file.rtf (0.4ms)
I, [2016-05-18T17:34:48.435946 #20202] INFO -- : [d02e8ea3-53da-440d-b3b1-cc6bfd6524dc] Completed 200 OK in 17ms (ActiveRecord: 4.4ms)
最佳答案
正如上面评论中详述的那样,解决方案是禁用link_to的turbolinks。对于 Turbolinks 5,这可以做到,如 here 所述通过使用 data-turbolinks="false"
<%= link_to "Foo", new_foo_path(@foo), data: { turbolinks: false } %>
关于ruby-on-rails - Rails 5 破坏了 send_file 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37310574/