Skip to content

Instantly share code, notes, and snippets.

@yihangho yihangho/gist:c2b78ec9edf69868b0e1 Secret
Last active Aug 29, 2015

Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rails CORS</title>
</head>
<body ng-app="app">
<div ng-controller="PostController">
<ul>
<li ng-repeat="post in posts">{{ post }}</li>
</ul>
Delete status: {{ deleteStatus }}.
</div>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
<script>
var app = angular.module('app', []);
app.controller('PostController', ['$scope', '$http', function($scope, $http) {
$scope.deleteStatus = "ongoing";
$http.get('http://localhost:3000/posts.json').success(function(data) {
$scope.posts = data;
}).error(function() {
console.log("Error getting posts")
});
$http.delete('http://localhost:3000/posts/1.json').success(function(){
$scope.deleteStatus = "done";
}).error(function() {
$scope.deleteStatus = "error";
});
}]);
</script>
</body>
</html>
@sebastialonso

This comment has been minimized.

Copy link

sebastialonso commented Mar 6, 2015

I'm getting exactly the same CORS error. Running rails sever on port 3000, running an http-server on port 8080 on Chrome, this code doesn't work.

edit: same thing on Firefox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.