I have an issue regarding Refile and its multiple file options when I perform validation of my forms.
When I send a form with attachments (let's say "docs A"), and the form doesn't succeed in its validation (let's say because email was required), refile has the following behaviour:
- If no other files are attached, and we resubmit the form (a valid one this time), "docs A" are persisted and moved from the cache to the store folder (all done by refile). This is all good.
- If other files ("docs B") are included in the form, and the latter is submitted, only "docs B" will be considered (no matter if the form was valid, or invalid, and despite the :append value -- check the models below). If the form was valid, only "docs B" will be persisted. If the form is invalid, once we make it valid and resubmit it, it will persist "doc B" (unless we attach new files).
"docs A" and "docs B" could be single files as well. It will happen the same behaviour.
I've got the following models
class User < ActiveRecord::Base
has_many :documents, dependent: :destroy
accepts_attachments_for :documents, append: true, attachment: :file
end
class Document < ActiveRecord::Base
belongs_to :user
attachment :file, type: :document
end
And in the form:
<%= f.attachment_field :documents_files, multiple: true, direct: true, presigned: true %>
I'm using refile 0.5.5.
I've already tried to include hidden inputs
<% @user.documents.each do |doc| %>
<%= f.hidden_field "documents_files", multiple: true, value: {id: doc.file_id, filename: doc.file_filename, size: doc.file_size} %>
<%# end %>
But they get "overriden" if new attachments are included.
I was wondering if the multiple and append behaviour of refile are actually working, or whether my implementation is incorrect.
The expected behaviour is that new attachments should get appended to the existing ones (i.e. "docs A" + "docs B").
I'd appreciate any help!