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