Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple File upload? #272

Open
samnymr opened this issue Dec 27, 2019 · 3 comments
Open

Multiple File upload? #272

samnymr opened this issue Dec 27, 2019 · 3 comments

Comments

@samnymr
Copy link

samnymr commented Dec 27, 2019

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!

@spohlenz
Copy link
Member

spohlenz commented Jan 1, 2020

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.

@coezbek
Copy link
Contributor

coezbek commented Dec 14, 2021

@Timmitry
Copy link

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:

  1. 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
  2. Set rails config option config.active_storage.replace_on_assign_to_many = false - however, this changes the behaviour for the whole application! (Related Issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants