title: Can I download a CSV file with `remote: true` on a Rails form?
body: <p>I'm building a very simple single-page Rails app with a single form using the <code>remote: true</code> option. Basically, the use selects a few options on the form, and I render a set of products matching these requirements back to the page using the <code>create.js.erb</code> view. So far, so good. </p>
  
  <p>I'd also like to give the user the option to download a CSV list of the products. The problem is, with the <code>remote: true</code> option, I can't figure out how to actually trigger the download. I can use the hack <a href="https://stackoverflow.com/questions/23159911/override-the-respond-to-format-with-form-button-in-rails-3">here</a> to route to the correct format and action:</p>
  
  <pre><code>&lt;%= button_tag( 'Download CSV', :value =&gt; 'csv', :name =&gt; 'format' ) %&gt;
  </code></pre>
  
  <h1> </h1>
  
  <pre><code>def create
    respond_to do |format|
      format.js
      format.csv { send_data @products.to_csv }
    end
  end
  </code></pre>
  
  <p>This almost works; the correct CSV (text) data is returned in the browser response when I click the "Download CSV" button -- but it doesn't get rendered or trigger a file download, presumably because it's being returned in an AJAX response. </p>
  
  <p>I could make this work by using a link, rather than submitting the form (assuming the action responds to 'GET'):</p>
  
  <pre><code>&lt;%= link_to 'Download CSV', products_path(format: :csv) %&gt;
  </code></pre>
  
  <p>But then I don't have access to the user data about the product requirements captured in the form parameters. </p>
  
  <p>Is there any way to make this work, or do I need to lose the <code>remote: true</code> and submit the form via HTML (non-AJAX) to trigger the CSV download?</p>