title: Export CSV file (without changing the page)
body: <p>show.html.erb</p>
  
  <pre><code>&lt;%= link_to "Export", {:action =&gt; :export}, :method =&gt; :post%&gt;
  </code></pre>
  
  <p>record_controller.rb</p>
  
  <pre><code> def export
     csv_file = CSV.generate({}) do |csv|
     csv &lt;&lt; @data_filtered.first.keys
     @data_filtered.each do |hash|
       csv &lt;&lt; hash.values
     end
   end
   send_data csv_file, :type =&gt; 'text/csv; charset=iso-8859-1; header=present', :disposition =&gt; "attachment; filename=tester1.csv"
  end
  </code></pre>
  
  <p>I am wondering how to do this because @data_filtered is an instance variable sent to show.view but it no longer exists when I click export (this is the data i want to export to a .csv).  Is there a way to pass this data through link_to?  I am also anticipating the issue that this is going to change the view which I dont want to do.</p>