title: Using ajax to download a file
body: <p>I have a javascript file that uses ajax and passes an array of ids to a rails controller action. The controller then maps these to model objects and generates a file containing some of their data. My problem lies in downloading this file.</p>
  
  <p>Before, I was saving the needed objects in the database first, and then the controller could just format as .ics, call the same action, then the file would be downloaded.</p>
  
  <p>Now everything is more dynamic, and I'm having trouble rendering the file now that I have to pass in params. Is there a way to do this? I've tried</p>
  
  <pre><code>render :layout =&gt; false, :text =&gt; @calendar.to_ical
  </code></pre>
  
  <p>and</p>
  
  <pre><code>send_data @calendar.to_ical, :type=&gt; 'text/ics'
  </code></pre>
  
  <p>and</p>
  
  <pre><code>render :text =&gt; @calendar.to_ical
  </code></pre>
  
  <p>All of which complete successfully, but no file is ever downloaded.</p>
  
  <p>Any help would be appreciated! Thank you!</p>