Open samnymr opened 4 years ago
The file_field
helper works the same as the corresponding Rails form helper (https://api.rubyonrails.org/v6.0.2.1/classes/ActionView/Helpers/FormHelper.html#method-i-file_field) so you can add support for multiple file uploads with:
file_field :attachments, multiple: true
Your models will also need to be hooked up correctly with something like ActiveStorage or Shrine.
Documented here: https://github.com/TrestleAdmin/trestle/wiki/Form-Fields#file-field
The file_field :attachments, multiple: true
works so far. However, when editing an entity that already has attachments, this might destroy all old attachments and replace them with the new ones. That is due to built-in behaviour of Rails, which was changed from 5.2 to 6.0. There are different ways to keep the old attachments:
Add hidden fields with the existing attachments (related Issue)
record.attachments.each do |attachment|
hidden_field :attachments, multiple: true, value: attachment.signed_id
end
file_field :attachments, multiple: true
Set rails config option config.active_storage.replace_on_assign_to_many = false
- however, this changes the behaviour for the whole application! (Related Issue)
Hiya,
I've been looking for multiple file upload, I'm currently using the file_field option.
Is it possible to have a multiple file upload system? I don't know if I'm missing something haha!