Downloadable file "on the fly"

M

Milo Thurston

I'd like to have a cgi script produce it's output
as a downloadable .csv file rather than displaying it on screen.
In perl, I used to do it this way:

@stuff = qw(some items in an array);
print $cgi->header(-TYPE => 'text/plain',
-EXPIRES => 'now',
-ATTACHMENT => 'download.csv');
foreach (@stuff) { print "$_\cI"; }
exit 0;

Any suggestions on doing the same with ruby? A direct translation
of the code doesn't seem to be very effective - I get only a blank
page.
Thanks for any suggestions.
 
T

ts

Try this (*not tested*)

M> @stuff = qw(some items in an array);

stuff = %w(some items in an array)

M> print $cgi->header(-TYPE => 'text/plain',
M> -EXPIRES => 'now',
M> -ATTACHMENT => 'download.csv');

puts cgi.header(
"type" => "text/plain",
"Date" => Time.now,
"Expires" => Time.now,
"Content-Disposition" => 'attachment; filename="download.cvs"')

M> foreach (@stuff) { print "$_\cI"; }

puts stuff.join("\t")


Guy Decoux
 
M

Milo Thurston

ts said:
Try this (*not tested*)
Thanks.

puts cgi.header(
"type" => "text/plain",
"Date" => Time.now,
"Expires" => Time.now,
"Content-Disposition" => 'attachment; filename="download.cvs"')


That was the main part that was giving be problems - I'll try it out.
Milo.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top