I think I found a reasonable rails solution to this problem.
In the images_controller.rb, instead of rendering the template as javascript, render the template as text using the render_to_string method and incapsulate it into the json response:
def create
# create! is really to simplify the example, in reality you want to use a background worker to
# attach the image to a model and maybe resize it, but this is not the point of the question
@image = Image.create!
set_standard_vars
render :json => { :success => true, :partial => render_to_string }
end
This will send the rendered create.js.erb template back to fineuploader into the json response. I then run the script using the eval JS method and the "on complete" callback:
$(function () {
'use strict';
$("div#button").fineUploaderS3({
debug: true,
uploaderType: 'basic',
button: $('div#button'),
validation: {
allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
sizeLimit: 3000000 // 3MB
},
objectProperties: {
key: function(fileId) {
var filename = $("div#button").fineUploader("getName", fileId);
return item_picture_bucket + "/" + filename;
},
acl: "public-read"
},
request: {
endpoint: "anglers-zoo.s3.amazonaws.com",
accessKey: access_key
},
signature: {
endpoint: signature_end_point,
customHeaders: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
}
},
uploadSuccess: {
endpoint: upload_url,
customHeaders: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
},
params: {
'hash': image_group,
'position': $('#button_slot').data('imageposition'),
}
},
}).on("submit", function(id, name) {
$('.destroy_image').hide();
$('#button').hide();
$("div#button").parent().find('#throbber').show();
disable_submit_button();
}).on("complete", function(event, id, name, responseJSON, xhr){
jQuery.globalEval(responseJSON.partial);
});
});
It is still not 100% the rails way, but it is clean and rails-sy enough for me.