Rails 5破坏了send_file方法?

时间:2016-05-18 21:42:34

标签: ruby-on-rails download mime-types

我最近将我的应用程序升级到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)

1 个答案:

答案 0 :(得分:1)

正如上面评论中详述的那样,解决方案是禁用link_to的turbolinks。对于Turbolinks 5,这可以通过使用data-turbolinks="false"

描述here来完成
<%= link_to "Foo", new_foo_path(@foo), data: { turbolinks: false } %>