I have an angular frontend with a rails backend.
I have angular code like this:
$http({method: 'GET', url: 'http://localhost:3000/products.json'}).
success(function(data, status, headers, config) {
$scope.data = data;
}).
error(function(data, status, headers, config) {
$scope.status = status;
});
I kept getting the No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4000' is therefore not allowed access.
error, so I used https://stackoverflow.com/a/17815546/561634 so my config/application.rb has:
config.action_dispatch.default_headers = {
'Access-Control-Allow-Origin' => '*',
'Access-Control-Request-Method' => '*'
}
inside it. Unfortunately, this hasn't changed the error.
Thanks for all help!