title: Rails 3 - Tempfile Path?
body: <p>I have the following:</p>
  
  <pre><code>attachments.each do |a|
     Rails.logger.info a.filename
     tempfile = Tempfile.new("#{a.filename}", "#{Rails.root.to_s}/tmp/")
     Rails.logger.info tempfile.path
  end
  </code></pre>
  
  <p>Where attachments is from paperclip.</p>
  
  <p><strong>Here's the output:</strong></p>
  
  <pre><code>billgates.jpg
  /Users/bhellman/Sites/cline/tmp/billgates.jpg20101204-17402-of0u9o-0
  </code></pre>
  
  <p>Why is the file name getting <code>20101204-17402-of0u9o-0</code> appended to at the end? That's breaking everything with paperclip etc. Anyone seen this before? For the life of I have no idea what's doing it?</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE</strong>
  Paperclip: <a href="https://github.com/thoughtbot/paperclip/" rel="noreferrer">Paperclip on github</a></p>
  
  <p>a is the attachment file</p>
  
  <pre><code>tempfile = Tempfile.new("#{a.filename}", "#{Rails.root.to_s}/tmp/")
  tempfile &lt;&lt; a.body
  tempfile.puts
  attachments.build(
      :attachment =&gt; File.open(tempfile.path)
  )
  </code></pre>