title: export data to csv without changing pages
body: <p>What is the proper way to export data to a csv file from rails.</p>
  
  <p>I have an "export" link in my views</p>
  
  <p>shows.html.erb</p>
  
  <pre><code> &lt;%= link_to "CSV", patient_record_path(format: "csv") %&gt;
  </code></pre>
  
  <p>patient_record_controller</p>
  
  <pre><code>def show
  
      ....
      respond_to do |format|
          format.html
          format.csv {
          send_data RestClient.get(url, :accept =&gt; :csv), :type =&gt; 'text/csv; charset=iso-8859-1; header=present', :disposition =&gt; "attachment; filename=data.csv"
          }
      end
  end
  </code></pre>
  
  <p>When i click export I get the error</p>
  
  <pre><code>Template is missing
  
  Missing template patient_record/show, application/show with {:locale=&gt;[:en], :formats=&gt;[:csv], :handlers=&gt;[:erb, :builder, :coffee]}. Searched in: * "/RubymineProjects/my_app/app/views"
  </code></pre>
  
  <p>it is also redirected to the url </p>
  
  <pre><code>http://www.host.com/patient_record/1.csv
  </code></pre>
  
  <p>I shouldnt even be redirecting pages, i simply want to export a csv file and keep on the same page</p>
  
  <p>If I use ajax, the functionality works fine, but the file doesn't show up being downloaded in the broser</p>