# RE: Output non-HTML (CSV) from Rails

**URL:** <https://www.ruby-forum.com/t/re-output-non-html-csv-from-rails/95061>\
**Category:** Rails\
**Created:** [January 11, 2006, 9:38pm UTC](https://www.ruby-forum.com/t/re-output-non-html-csv-from-rails/95061 "2006-01-11T21:38:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 11, 2006, 9:38pm UTC](https://www.ruby-forum.com/t/re-output-non-html-csv-from-rails/95061/1 "2006-01-11T21:38:46Z")

</div>

Bakki K. wrote:

> Have you tried send\_data or send\_file which are " Methods for sending  
> files and streams to the browser instead of rendering." I have used  
> send\_data to send and image to the browser. Check out my howto …

[http://wiki.rubyonrails.com/rails/pages/HowtoSecureFormsWithNoisyImages](http://wiki.rubyonrails.com/rails/pages/HowtoSecureFormsWithNoisyImages)

Bakki,

Very nice! This seems to be the ideal way to solve the problem.

For some reason when rendering through the view (as Alex Y.  
suggested) I was getting ~6500 whitespace lines preceeding the start of  
my CSV data.

But using ‘send\_data’ in the controller seems to have solved that.

And I also just discovered how to direct the filename of the  
downloadable attachment file with an addition to the Content-Disposition  
header:

send\_data csv\_data, :type =\> ‘text/csv’, :disposition =\> ‘attachment;  
filename=output.csv’

Thank you Bakki, Alex, and Adam!

Matt

–  
Matt C. Wagner  
Information Security Analyst

Network Intrusion Detection  
Security Operations Center  
Corporate Information Security  
Wells Fargo Bank
