Using Angular-Resource to Connect to Rails

The Rails way of designing HTTP endpoints (which is a RESTful style[77]) isn’t particular to Rails. It’s quite common outside the Rails world. Because of this, it’s possible to use a higher level of abstraction than what $http gives us. The Angular module angular-resource provides such an abstraction.

What it will allow us to do is to write code like so:

 $scope.customer = Customer.get(customer_id);

Although there are no callbacks, this code is still asynchronous. Execution continues after the call; it doesn’t wait for the Ajax call to complete. This is because the object returned by Customer.get is a promise that, when resolved, will behave like a customer object, exposing the various fields from ...

Get Rails, Angular, Postgres, and Bootstrap now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.