If you are using the send_file command inside your controller to send a temporary file, you cannot delete that file after, or Rails will complaint the file is missing. That is because send_file works asynchronouly.

If that file is a temporary file you just created to serve that request, you’re in trouble, because you can’t remove it.

One solution is to get a cron job to periodically remove old files.

The other solution, is to set the :stream option of send_file to false. This will cause send_file to block while the file is being served to the client.

I think this os only supported in Rails 2.3.x because this option is missing from the Rails 3.0 documentation.

Also, be careful with big files, because when :stream is true Rails reads the whole file before sending it to the client.