我有一个发票模型。创建发票时,需要附件。这行得通。
如何在更新期间更换附件?我希望删除原始附件。当我在编辑屏幕上有相同的表单字段时,它不会在提交时更新。旧文件还在。此外,它显示“没有选择文件”,即使有一个。我可以单击查看附件,它显示得很好。
发票.rb
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
_form.html.erb
<label>Invoice Attachment: </label>
<%= f.file_field :attachment %>
<%= link_to 'View Attachment', @invoice.attachment.url %>