views:

385

answers:

1

Hi All,

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')"

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

A: 

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();

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.

Gabe Hollombe