Based on my understand from the restangular docs, calling Resource.getList('subElement',{query:param}) should make a call to /resource/subelement?query=param
I am using Ransack on top of a rails API, and I am attempting to pass some search parameters, which take the form "q[field_eq]=foo".
Here's a controller:
.controller('PlaypenCtrl', function PlaypenCtrl(
$scope,
Resource
) {
'use strict';
var qParams;
$scope.doIt = function() {
qParams = {
per_page: 10
};
qParams['q[some_field_eq]'] = 'foo';
console.log(qParams); //Object {per_page: 10, q[some_field_eq]: "foo"}
Resource.getList('subElement',qParams).then(function(list){
console.log(list);
});
};
});
When I call doIt, this gets logged:
Error: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'q[some_field_eq]' is not a valid HTTP header field name.
This makes sense, because obviously that is not a valid HTTP header field name.
The question is... why would Restangular be attempting to put the qParams object into the request headers? These should be request parameters, according to the docs.
If I take out the 'subElement', things work as expected:
$scope.doThat = function() {
qParams = {
per_page: 10
};
qParams['q[some_field_eq]'] = 'foo';
console.log(qParams); //Object {per_page: 10, q[some_field_eq]: "foo"}
Resource.getList(qParams).then(function(list){
//calls /resource?per_page=10&q%5Bsome_field_eq%5D=foo
console.log(list); //...a normal restangular list object, as expected
});
};
What am I missing?