Skip to content

Instantly share code, notes, and snippets.

@yihangho
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yihangho/c2b78ec9edf69868b0e1 to your computer and use it in GitHub Desktop.
Save yihangho/c2b78ec9edf69868b0e1 to your computer and use it in GitHub Desktop.
<!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
Copy link

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