Post by Peter Cooper on June 9th, 2006
Streaming programmatically generated content from Rails

- PX: A quick and silly Ruby obfuscation system
- Specify Rails Response Type via the URL
- 21 Useful Ruby (and Rails) Code Snippets


Rather than use the send_file or send_data methods to send an entire, completed bulk of information back to the client, David N. Welton wanted to, effectively, print stuff to the client bit by bit. He worked out how to do it and presents his findings and sample code here.
A preview of his 'output data to CSV line by line' method:
def generate_file @headers["Content-Type"] = "text/comma-separated-values;" @headers["Content-Disposition"] = "filename=\"some.file.txt\";" i = 0 render :text => Proc.new { |response, output| ... output.write("some generated text...") ... }, :layout => false end

Click here to add on del.icio.us
Tweet This








