# Tempfiles

**URL:** <https://www.ruby-forum.com/t/tempfiles/142732>\
**Category:** Rails\
**Created:** [July 10, 2008, 11:01pm UTC](https://www.ruby-forum.com/t/tempfiles/142732 "2008-07-10T23:01:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![crunch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crunch](https://www.ruby-forum.com/u/crunch)\
**Post date:** [July 10, 2008, 11:01pm UTC](https://www.ruby-forum.com/t/tempfiles/142732/1 "2008-07-10T23:01:02Z")

</div>

I’m trying to get Tempfiles to work but they randomly disappear. It  
is very likely that I do not know how they work. This is what I want  
to do…if you think there’s a better and accepted approach please let  
me know.

I’m parsing icalendar data. I want to fetch the data from an  
uploaded .ics file or from Zimbra only once. So I need to store the  
data somehow during processing then discard it later. Tempfile seems  
like the thing to use. Here’s my code…

def createTempFile(cal)  
temp\_file = Tempfile.new(“calendar”)  
calendar\_file = File.new(temp\_file.path, “w+”)  
calendar\_file.puts(cal.to\_ical)  
calendar\_file.close  
session[:calendar\_path] = temp\_file.path  
logger.info “TEMPFILE: #{temp\_file.path}”  
end

I then pull the path from the session so I can use it in other  
functions in the same controller. Sometime it disappears from the  
temp directory sometimes it does not and I’m able to process it.

Am I missing something fundamental about how Tempfile works?

Thanks for your help!
