Skip to content

Instantly share code, notes, and snippets.

@rockwood
Last active August 29, 2015 14:01
Show Gist options
  • Save rockwood/d709673af91b6469f417 to your computer and use it in GitHub Desktop.
Save rockwood/d709673af91b6469f417 to your computer and use it in GitHub Desktop.
RailsResourceCollectionExtension
angular.module("rails").factory "RailsResourceCollection", (_) ->
class RailsResourceCollection
constructor: (models=[]) ->
@models = models
angular.module("rails").factory "RailsResourceCollectionMixin", (RailsResourceCollection) ->
RailsResourceCollectionMixin = ->
RailsResourceCollectionMixin.extended = (Resource) ->
Resource.intercept "afterResponse", (result, resource, context) ->
if angular.isArray(result)
result = new RailsResourceCollection(result)
result
RailsResourceCollectionMixin
angular.module("icurio").config (RailsResourceProvider) ->
RailsResourceProvider.extensions('collection')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment