need help with carrierwave - multiple vs single file upload


i want to have one uploader, but 2 forms:

Upload Single Attachment

<%= simple_form_for( do |form| %> <%= form.error_notification %>
<%= form.file_field :singlefile %>

<%= form.input :folder_id , :as => :hidden , :input_html => { :value =>} if @folder_current %>

<%= form.input :comment %>
<%= form.input :tags %>
<%= form.button :submit %>
<% end %>

Upload Multiple Attachments

<%= simple_form_for(, :html => { :multipart => true } ) do |form| %> <%= form.error_notification %>
<%= form.file_field :files, multiple: true, name: "folder_attachments[files][]" %>

<%= form.input :folder_id , :as => :hidden , :input_html => { :value =>} if @folder_current %>

<%= form.button :submit %>
<% end %>

–> no matter what i do, i always get errors on controller leve, eg: map or others. can an uploader only have 1 mount?

class FolderAttachment < ApplicationRecord

belongs_to :folder

mount_uploaders :singlefile, FolderAttachmentUploader

mount_uploaders  :files, FolderAttachmentUploader



“always get errors”, show the errors then

Also, use “mount_uploader” singular for the single file and “mount_uploaders” plural for the multiple files

ok, the plural got me beyond an error message, but i cant see the uploaded multiuploaded files. singles files work.

controller code:

@folder_attachment =
@folder_attachment.company_id = current_user.cid
@folder_attachment.user_id =

@folder = Folder.find_by_id(params[:folder_attachment][:folder_id])
respond_to do |format|
    format.html { redirect_to @folder , notice: 'Attachment was successfully created.' }
  #  format.json { render :show, status: :created, location: @folder_attachment }
    format.html { render :new }
   # format.json { render json: @folder_attachment.errors, status: :unprocessable_entity }

def folder_attachment_params
params.require(:folder_attachment).permit(:company_id, :folder_id, :singlefile, :comment,:tags, {files: []})

I think your problem is here

<%= form.file_field :files, multiple: true, name: “folder_attachments[files][]” %>

use “folder_attachment[files][]”, note “folder_attachment” singular, not plural since the form is for a single folder_attachment (and that’s on your folder_attachment_params method)

yep - its working.
but, can i get the array of filenames in case of multiupload in to the same db field and or vice versa? eg:

mount_uploader :files, FolderAttachmentUploader
mount_uploaders :files, FolderAttachmentUploader

I don’t think you can use the same attribute name for single and multiple attachments at the same time. What you can do is to always have multiple files and attach only one file when you get a single file upload. I don’t understand the use case of your idea.

I mean: multiple files can be zero or more, it includes the possibility of having only 1 file attached.

if i do multiupload, how could i add comments and additional fields to ‘each’ file during upload!?

If you need extra fields for each attachment then you need an extra model to store that data and the carrierwave file for each file you upload. Given the name of the model “FolderAttachment” it looks like that’s the model and that it shouldn’t have multiple files, it looks like there should be multiple FolderAttachments with only one file each.