问题描述
请告诉我这是如何工作的,因为我不明白......这是我的简单代码:
路线:
get 'download' =>'pages#download'
我的行动:
def 下载send_file "#{Rails.root}/public/downloads/robots.zip", :type=>"application/zip"
和下载链接:
所以,当我点击链接时,我得到了这个:
图片 http://joxi.ru/GrqvQ3xHlbaYmz.jpg
似乎浏览器正在尝试显示 zip 文件内容...但是当我从浏览器(或刷新页面)打开操作时,它工作正常.
为什么当我点击link_to
生成的链接时它不起作用?
添加 disposition: "inline"
而不是 disposition: "attachment"
对我有用.>
Please tell me how this works, because I don't understand... Here is my simple code:
Route:
get 'download' =>'pages#download'
My action:
def download
send_file "#{Rails.root}/public/downloads/robots.zip", :type=>"application/zip"
And download link:
<%= link_to "download", download_path %>
So, when i'm clicking on the link I get this:
Image http://joxi.ru/GrqvQ3xHlbaYmz.jpg
It seems like the browser is trying to show zip file content... But when I open the action from my browser (or refresh page) it's working fine.
Why doesn't it work when I click on the link generated by link_to
?
Adding disposition: "inline"
instead of disposition: "attachment"
worked for me.
这篇关于Send_file 在浏览中打开文件而不是下载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!