RE: Output non-HTML (CSV) from Rails

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

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