NAME
image_cache.rb
DESCRIPTION
a small utility library to facility caching image uploads between form
validation failures. designed for rails, but usable anywhere.
USAGE
in the controller
def upload
@image_cache = ImageCache.for(params, :image)
@record = Model.new(params)
if request.get?
render and return
end
if request.post?
@record.save!
@image_cache.clear!
end
end
in the view
<input type='file' name='image />
<%= @image_cache.hidden %>
<!-- optionally, you can show any uploaded image -->
<% if url = @image_cache.url %>
you already uploaded: <img src='<%= raw url %>' />
<% end %>
in a rake task
ImageCache.clear! ### nuke old files once per day