title: How to download a CSV file in Ruby on Rails?
body: <p>In my <code>InvoicesController</code> I have this:</p>
  
  <pre><code>def index
    @invoices = current_user.invoices
    respond_to do |format|
      format.html
      format.xls
      format.csv # not working!
    end
  end
  </code></pre>
  
  <p>In my <code>index.html.erb</code> view I have these two download links:</p>
  
  <pre><code>&lt;%= link_to "Download as Excel", invoices_path(:format =&gt; "xsl") %&gt;
  &lt;%= link_to "Download as CSV", invoices_path(:format =&gt; "csv") %&gt;
  </code></pre>
  
  <p>The templates <code>index.xsl.erb</code> and <code>index.csv.erb</code> do exist as well.</p>
  
  <p>The first link works, i.e. the Excel file gets downloaded to the user's computer. However, the CSV file is rendered in the <em>browser</em> and not downloaded.</p>
  
  <p>What must I do to enable users to download CSV files as well?</p>
  
  <p>Thanks for any help.</p>