Created
August 3, 2012 20:19
-
-
Save kapkaev/3251162 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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