Using after_filter to remove image after render

Hi Everyone,

I tried doing this and it's not working as I would expect it, but I'm
not sure if it's even possible. I have an app that generates and image
on request and displays it to the user. To cut back on storage, and
some security, I'd like the app to receive the view request, render
the image, display it, then delete the file. I know this isn't the
most efficient way to do things, but it's what I'd like to do.

Right now I have an after filter that removes the file fine, but it
happens before it displays, so I always get a broken image. If I take
that filter out, it works fine.

Am I doing something wrong, or is this just not possible?

My filter looks like this:

def remove
  if logged_in?
    user = User.find(session[:user_id])
    @image = Image.find(params[:id])
    if @image.user_id =
        if File.exist?('PATH TO IMAGE')
            File.delete('PATH TO IMAGE')

and in the controller I have this:

after_filter :remove, :only => [:show]