如何在rails中使用link_to_remote调用文件下载? [英] How do you invoke a file download with link_to_remote in rails?

查看:305
本文介绍了如何在rails中使用link_to_remote调用文件下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用link to remote来从rails调用文件下载。我的链接工作正常,看起来像这样:

I'd like to be able to invoke a file download from rails using link to remote. I have the link working okay,it looks like this :

link_to_remote image_tag("icons/ppt_48.png"),
   :url => formatted_element_path(@element, :ppt),
   :method => :get,
   :with => "'stoplight=' + $F('stoplight')"

响应包含正确的文件,但是当响应进来时,下载对话框不会出现。有没有办法调用下载对话?我需要这个工作在IE和firefox

The response contains the proper file, but the download dialogue doesn't appear when the response comes in. Is there a way to invoke the download dialogue? I need this to work in IE as well as firefox

thx,

-C

推荐答案

An 来自ParticleTree的文章提到了一个简单有效的解决方案,其中不涉及AJAX ,但确实导致文件下载,而不会使用户离开当前页面:

An article from ParticleTree mentions a simple and effective solution that doesn't involve AJAX at all, but does cause a file to download without the user leaving the current page:

<form id="super_form" method="post" action="/file/">
    <input type="hidden" id="download" name="download" />
</form>

$('download').value = 'top10';
$('super_form').submit();

这不直接回答您关于如何通过AJAX请求下载文件的问题,但是我认为这将给您的最终用户您正在寻找的经验。

This doesn't directly answer your question about how to have a file download via an AJAX request, but I think this will give your end-user the experience you're looking for.

这篇关于如何在rails中使用link_to_remote调用文件下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆