Ruby on Rails send_file doesn't work until i refresh the page?

后端 未结 4 1120
执念已碎
执念已碎 2020-12-11 10:39

I am working on a Rails server which I can download my locally stored movies and anime etc from. This is kind of working but when I click the download link I have to refresh

4条回答
  •  Happy的楠姐
    2020-12-11 11:27

    Try setting the disposition to attachment in send_file:

    class DownloadController < ApplicationController
      def index
        ...
        send_file( @path, :disposition => 'attachment' )
      end
    end
    

    The issue may be that your browser is trying to open the file itself - :disposition => 'attachment' prompts the browser to download the file, even if it thinks the file is something that it can open.

提交回复
热议问题