2

I am trying to pass some params to a resource call to get only the votes matching those params

It seems to be ignoring those params on a query because it just returns all of the votes regardless of params

Also when attempting to use get like this post suggests: Angular 1.0.8 $resource with multiple optional get parameters it gives error: expected object but got an array

What is the issue here?

Service

 wrmcServices.factory 'Vote', ($resource) ->
   $resource 'api/v1/votes.json',{},
     query:
       method:'GET'
       params:
         voteId:'votes'
       isArray:true

Note: I also tried removing the params: voteId:'votes' but it made no difference, if anyone wants to tell me what this does in this case it would be good to know, i just added that part from a tutorial

My query and get attempts

Vote.query({votable_id:scope.votableId,votable_type:scope.votableType});
Vote.get({votable_id:scope.votableId,votable_type:scope.votableType});
Community
  • 1
  • 1
Weston Ganger
  • 6,324
  • 4
  • 41
  • 39
  • perhaps something like this: $resource 'api/v1/votes.json', {votable_id: '@votable_id', votable_type: '@votable_type'}, ... – Jake Johnson Aug 28 '14 at 18:23
  • But this will be used in other cases too, i shouldnt have to specify any and all parameters that i could possibly be using in the service. And that doesnt work anyways. – Weston Ganger Aug 28 '14 at 18:30

1 Answers1

1

I solved it, the working code is as follows:

var $scope.vote;
Vote.get({votable_id:scope.votableId,votable_type:scope.votableType}, function (result){
  $scope.vote = result
});

or

var $scope.votes;
Vote.query({votable_id:scope.votableId,votable_type:scope.votableType}, function (result){
  $scope.votes = result
});
Weston Ganger
  • 6,324
  • 4
  • 41
  • 39