Skip to content

Instantly share code, notes, and snippets.

@kapkaev
Created August 3, 2012 20:19
Show Gist options
  • Save kapkaev/3251162 to your computer and use it in GitHub Desktop.
Save kapkaev/3251162 to your computer and use it in GitHub Desktop.
def create
@post = Post.find_by_slug(params[:post_id])
@image = @post.images.build(params[:image])
if @image.save
respond_to do |format|
format.js
end
end
end
jQuery.ajaxSetup({
'beforeSend': function(xhr) {
xhr.setRequestHeader("Accept", "text/javascript")
}
})
$('#image_image').change(function() {
jQuery.each($('#image_image')[0].files, function(i, file) {
var data = new FormData();
data.append("image[image]", file);
$.ajax({
url: 'images',
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment