0

I am searching for an easy solution how to multi upload more than one file.

The idea is that it should use polymorphic association, so I dont have to write another model for every model that will use attachment.

But I am stucked in how to join everything together.

Can please anybody show me the way how to use polymorphic association with multi file upload, eventually what is the best approach? Now I use Dragonfly so I thought it would be useless to use for example Carrierwave. I am asking because there is no detailed explanation of this problem.

**Attachment model:**
belongs_to :filable, polymorphic: true
dragonfly_accessor :file

**Parameters of attachment:**
file_uid (Dragonfly field)
file_name (Dragonfly field)
filable_id (polymorph)
filable_type (polymorph)

**Project model:**
has_many :attachments, as: :filable

So this is my code so far. Now how can I use form builder to upload multiple files?

Boomerange
  • 616
  • 1
  • 10
  • 18
  • We need the code and detailed explanation, sorry – Fabrizio Bertoglio Mar 17 '17 at 08:02
  • @FabrizioBertoglio Hi Fabrizio, I added code that I have so far. Attachment is polymorphic structure for uploading the multiple files. – Boomerange Mar 17 '17 at 17:27
  • unluckly I am very busy right now. I have done this functionality based on carrierwave. With carrierwave there are two ways of doing it. It depends on the database you are using. http://stackoverflow.com/questions/21411988/rails-4-multiple-image-or-file-upload-using-carrierwave https://github.com/carrierwaveuploader/carrierwave – Fabrizio Bertoglio Mar 18 '17 at 10:24
  • You included Carrierwave in your tags, so I give you a couple of infos. If you are using the latest versions of Mysql or postrgresql, it is very easy with carrierwave, bacause you just use a filed with data type json. Read more at the following link. https://github.com/carrierwaveuploader/carrierwave#multiple-file-uploads – Fabrizio Bertoglio Mar 18 '17 at 10:27
  • @FabrizioBertoglio Correct me if I am wrong, but the answer from docs is only on one question - multiple files upload. But not on polymorphic multi files upload. – Boomerange Mar 20 '17 at 19:57

0 Answers0