I have coped with this problem and made a demo app to show how to do this.
In short I have two models: item and upload.
item.rb:
has_many :uploads
accepts_nested_attributes_for :uploads, :allow_destroy => true
upload.rb:
belongs_to :item
has_attached_file :upload, :styles => { :large => "800x800", :medium => "400x400>", :small => "200x200>" }
I added uploads_attributes
to item controller.
Now you can add jquery-file-upload form to your view, but there is one problem: it sends each photo in separate requests. So there is my jquery-file-upload initializer, which uploads all photos in one request (creating item model) and then redirecting to the root of your app (you need to use item form):
<script type="text/javascript" charset="utf-8">
var num_added = 0;
var added = 0;
var all_data = {};
$(function () {
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
complete: function (e, data) {
window.location = "<%= root_url %>";
},
singleFileUploads: false
}) .bind('fileuploadadd', function (e, data) {num_added++;})
.bind('fileuploadsubmit', function (e, data) {
if(added < num_added)
{
if (added == 0)
all_data = data;
else
{
$.each(data['files'], function(i, file){
all_data['files'].push(file);
});
$.each(data['context'], function(i, context){
all_data['context'].push(context);
});
}
added++;
if (added == num_added)
{
added++;
all_data.submit();
}
return false;
}
})
.bind('fileuploadsend', function (e, data) {num_added = 0; added = 0;});
//
// Load existing files:
$.getJSON($('#fileupload').prop('action'), function (files) {
var fu = $('#fileupload').data('blueimpFileupload'),
template;
fu._adjustMaxNumberOfFiles(-files.length);
console.log(files);
template = fu._renderDownload(files)
.appendTo($('#fileupload .files'));
// Force reflow:
fu._reflow = fu._transition && template.length &&
template[0].offsetWidth;
template.addClass('in');
$('#loading').remove();
});
});
</script>