我在.erb如下:由send_file在轨不会下载到浏览器 - 而不是在加载浏览器窗口中直接
<%= link_to 'Download PDF', planners_download_pdf_url %>
我有以下的方法来应对:
def download_pdf
send_file(
"#{Rails.root}/Thing/ex/example.xls",
filename: "mything.xls",
type: "application/xls"
)
end
我路线有:
get '/planners/download_pdf'
当我点击我的链接,该方法确实被调用。我的问题是,不下载到浏览器。相反,它需要我在浏览器中打开的选项卡并将文件转储为HTML。像......你见过在记事本中打开过的Excel文件吗?它这样做。请看下图:
我如何得到这个,而不是下载的文件?
我希望这有助于你
[https://stackoverflow.com/questions/13164063/file-download -link-in-rails](https://stackoverflow.com/questions/13164063/file-download-link-in-rails) –
如果你使用'send_data',会发生什么?另外,你与'pdf ''VS :) xls'我 –