-
Notifications
You must be signed in to change notification settings - Fork 1.7k
How to: keep (not replace) files on nested edits
mpoli edited this page Sep 22, 2013
·
1 revision
Using: Rails4, Carrierwave, nested_form, simple_form and haml
Normally, when you have a Model that has many Files and you have the Files nested in the Model edit form, the File objects that already exist get replaced if you upload a new file.
To prevent that, in your view:
= simple_nested_form_for @model, :html => { :multipart => true } do |f|
= f.simple_fields_for :files do |p|
- if p.object.new_record?
= p.file_field :file
- else
= image_tag p.object.file.url(:thumb).to_s
%br
= p.link_to_remove t(:remove)
= f.link_to_add t(:add), :files
.form-actions
= f.button :submit, :class => 'btn-primary'
= link_to t('.cancel', :default => t("helpers.links.cancel")), properties_path, :class => 'btn'