# Uploading multiple files with will\_paginate

**URL:** <https://www.ruby-forum.com/t/uploading-multiple-files-with-will-paginate/176821>\
**Category:** Rails\
**Created:** [October 6, 2009, 6:06pm UTC](https://www.ruby-forum.com/t/uploading-multiple-files-with-will-paginate/176821 "2009-10-06T18:06:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [October 6, 2009, 6:06pm UTC](https://www.ruby-forum.com/t/uploading-multiple-files-with-will-paginate/176821/1 "2009-10-06T18:06:28Z")

</div>

hey all

i’m using attachment\_fu to add ‘documents’ (the attached class) to a  
forum post (in our app). It’s all working fine for a single document -  
on the new post page i just have a file\_field which sets  
“post[document]”, which calls my Post#  
document= method, which builds a document for that post:

def document=(file)  
self.documents.build(:uploaded\_data =\> file)  
end

Then the post is saved and it’s all good.

I thought it would be nice to be able to add multiple documents at once.  
So, instead of writing to “post[document]” in the form, i’m writing to  
“post[documents][]”, and i get an array of files through. I then do  
this -

def documents=(files)  
files.each{|file| self.document = file}  
end

expecting that this would build three documents, and that when i saved  
the post then the documents would get created. However, i’m getting  
this error, when i try to do the Post.build(params[:post]) in the  
controller:

Document(#-635202458) expected, got  
ActionController::UploadedTempfile(#-613987618)

Is it the case that there’s some rails magic going on here, and we’re  
not really dealing with file objects after all, but a tempfile, of which  
there can only be one? (like in highlander) Or something else?

Grateful for any guidance…  
max
