Topic: Paperclip - Replace Existing Attachment with New

I have an invoice model.  When I create an invoice, an attachment is required.  This works.

How can I replace the attachment during an update?  I want the original attachment to be deleted.  When I have the same form field on the edit screen, it does not update upon submission.  The old file is still there.  Also, it shows "no file chosen", even though there is one.  I can click on View Attachment and it displays just fine.


has_attached_file :attachment,
  :url => "http://...../attachments/:id/:style/:basename.:extension",
  :path => ":rails_root/public/attachments/:id/:style/:basename.:extension"
  validates_attachment_presence :attachment
  validates_attachment_size :attachment, :less_than => 5.megabytes


<label>Invoice Attachment: </label>
<%= f.file_field :attachment %>

<%= link_to 'View Attachment', @invoice.attachment.url %>

Last edited by CharlieB123 (2012-11-19 14:51:10)