I'm using rails 3.2 with angularjs, and I'm trying to understand how to use angular's $resource.
I would like resource to return the results from a non-default action (so not get, save, query, remove, and delete)
So in my Posts controller I have
def home
@recent_posts = Post.recent_posts
respond_to do |format|
format.html
format.json
end
end
And then in my js file I have
app.factory "Post", ["$resource", ($resource) ->
$resource("/post/:id/:action", {id: "@id"}, {home: {method: "GET", isArray: true}})
]
@HomeCtrl = ["$scope", "Post", ($scope, Post) ->
$scope.recent_posts = Post.home()
]
In my view if I try and do something like ng-repeat="post in recent_posts", it's not returning anything.
$scope.recent_posts = Post.home({action:'home', function(response){console.log(response) }, function(response){console.log(response)} }). Please have these callbacks registered and check whats coming in the response. The first function is the success callback, the second one is the error callback.