I have a front end web app in Angular and back end in Rails. From front-end I have javascript code issuing POST http request:
$scope.onSave = function () {
$http.post('http://localhost:3000/documents', { user: $scope.user, formData: $scope.formData }, function (response) {
$scope.isSaved = true;
console.log(response);
if (response.success) {
console.log("It has been successfully saved!")
}
});
}
And on submit button, I call above function:
<button type="submit" class="btn btn-success" ng-click="onSave()">Submit</button>
Then I get an error saying
XMLHttpRequest cannot load http://localhost:3000/documents. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3001' is therefore not allowed access. The response had HTTP status code 404.
I know i need to allow cross domain access but I'm not sure how I can achieve this in Rails server side.