$(function() {
$('a').click(function(e){
$.ajax({
data: "{\"item\":{\"name\":\"foobar\"}}",
type:'POST',
url:'http://localhost:3000/items/upload',
success: function(response) {
alert('Successfully sent data!');
},
error: function(event, jqXHR, ajaxSettings, thrownError) {
}
});
});
});
</script>
match '/ items / upload' => "items # upload",: условие => {: method =>: параметры}
def upload
#Needs these headers for the cross-domain ajax
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
headers['Access-Control-Allow-Headers'] = 'x-requested-with'
if request.post?
@item = Item.new(params[:item])
@item.pic = data
@item.save!
end
render :text => 'success'
end