我最近将我的应用程序升级到Rails 5,我的下载停止了工作。当我点击下载按钮时,浏览器挂起,没有任何反应。
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)
答案 0 :(得分:1)
正如上面评论中详述的那样,解决方案是禁用link_to的turbolinks。对于Turbolinks 5,这可以通过使用data-turbolinks="false"
<%= link_to "Foo", new_foo_path(@foo), data: { turbolinks: false } %>