jBeas
jBeas

Reputation: 926

Multiple File Uploads for a new record

I have implemented multiple file uploads for existing records as seen here https://github.com/websymphony/Rails3-Paperclip-Uploadify

I would like to know if it is possible to implement multiple file uploads when creating a new record.

Since we need flash to do the multiple file uploads, how would it be possible to associate the uploaded files with the record if the record has not yet been created.

I have thought of a hack-ish way to essentially make a "draft" and update it. However, I hope there is a better way to do this.

Upvotes: 2

Views: 1123

Answers (2)

Johnny Woo
Johnny Woo

Reputation: 1036

Yes, you can use http://blueimp.github.com/jQuery-File-Upload/. But there are still some points you need to be careful.

  1. Don't forget to remove appended array after you define the file field with "multiple". For example: replace "photo[image][]" with "photo[image]".Otherwise file uploaders like "carrierware" will not be working.
  2. If you are using rails 3.2.13, the appended array will always appear no matter whether you set the name to be without appended array. You can use "file_field_tag" to resolve this problem. Please refer this issue to: https://github.com/tors/jquery-fileupload-rails/issues/36.

For the association:

  1. You need to create a hidden text field which contains IDs of images that will be associated to the record you are going to create.
  2. Upload images by "jquery-fileupload"(it is ajax), then get IDs of images from response bodies.
  3. Set these IDs to the hidden field.

Upvotes: 1

apneadiving
apneadiving

Reputation: 115511

There is no better than the kind of hackish way you present:

  • creating orphans objects and give them parents later or delete them (sad huh? :) )

  • creating parent object by default, add some confirmation field in the form so that you know what objects really have an owner, delete the rest.

BTW, you don't "need" flash for multiple uploads, see here: http://blueimp.github.com/jQuery-File-Upload/

Upvotes: 4

Related Questions