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

后端 未结 4 1123
执念已碎
执念已碎 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条回答
  •  醉酒成梦
    2020-12-11 11:10

    Are you using turbolinks? Turbolinks apparently doesn't play nicely with send_file (https://github.com/rails/turbolinks/issues/182). Try adding "data: { no-turbolink: true }" (or "'data-no-turbolink'=>true") in the link_to helper, e.g.:

    <%= link_to "Downloadable File", downloadable_file, data: { no-turbolink: true } %>
    

    See also: Rails 4, asset pipeline causes user downloadable files to be downloaded twice, rails won't send_data as file, Ruby on Rails send_file, code in controller action running twice

提交回复
热议问题