Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5 broke send_file method?

I have recently upgraded my application to Rails 5 and my downloads stopped working. When I click download button, browser hangs and nothing happens.

class DownloadsController < ApplicationController
  def download
    send_file(
      "#{Rails.root}/public/file.rtf",
      filename: "file.rtf",
      type: :rtf,
      disposition: "attachment"
    )
  end
end

I have rtf mimetype

Mime::Type.register "text/richtext", :rtf

Logs showing that everything is ok

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)
like image 410
Ilya Cherevkov Avatar asked Oct 19 '22 09:10

Ilya Cherevkov


1 Answers

As it was detailed in above comments, the solution is to disable the turbolinks for link_to. This can be done, for Turbolinks 5, as it is described here by using data-turbolinks="false"

<%= link_to "Foo", new_foo_path(@foo), data: { turbolinks: false } %>
like image 157
mmsilviu Avatar answered Nov 03 '22 08:11

mmsilviu