How do you invoke a file download with link_to_remote in rails?

前端 未结 1 796
名媛妹妹
名媛妹妹 2021-01-14 04:30

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(\         


        
相关标签:
1条回答
  • 2021-01-14 04:36

    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.

    0 讨论(0)
提交回复
热议问题