title: clean /tmp when send_file is over
body: <p>I have a Redmine plugin. I create a temporary file in /tmp, then I send it with File.open. I want to delete the temporary file when user has download it. How can I do ?</p>
  
  <p>My code (in a controller):</p>
  
  <pre><code>File.open(filelocation, 'r') do |file|
    send_file file, :filename =&gt; filename, :type =&gt; "application/pdf", :disposition =&gt; "attachment"
  end
  </code></pre>
  
  <p>If I remove the file after File.open, it doesn't work.</p>
  
  <p>EDIT</p>
  
  <p>In my controller I do:</p>
  
  <pre><code>def something
    temp = Tempfile.new(['PDF_','.pdf'])
    # ... some code that modify my pdf ...
  
    begin
      File.open(temp.path, 'r') do |file|
        send_file file, :filename =&gt; temp.path, :type =&gt; "application/pdf", :disposition =&gt; "attachment"
      end
  
    ensure
      temp.close
      temp.unlink
    end
  
  end
  </code></pre>
  
  <p>My temporary file is remove, but not in the end of my code: the File.open return a damage PDF.</p>