James Gray
2/7/2008 9:16:00 PM
On Feb 7, 2008, at 2:44 PM, Mark Mr wrote:
> HI, I'm currently using the FasterCSV library to pull a bunch of data
> from my database and send a .csv file to the user. Currently i start
> off
> with
>
> FasterCSV.open("app/models/" + @assessment.assessment + ".csv", "w")
> do
> |csv|
>
> write all the info to it, then i use
>
> send_file ('app/models/' + @assessment.assessment + '.csv')
>
> to send it. It saves the csv file on the server and then sends that
> file
> to the user. Is there any way to send the csv file without saving it
> to
> the server?
Yes, if you can easily hold the data in memory. You could use
FasterCSV.generate() to get the data in a String. The use send_data()
instead of send_file() to dump it to the client.
> Or is there a command i can use to delete the file after it
> sends?
Sure, use the standard Tempfile library to allocate a file, write to
it, and then feed it to send_file().
James Edward Gray II