2

The query-params-new flag set to true.

Using latest ember and ember data. Ember: 1.6.0-beta.1+canary.b5b90241 ember.js and Ember Data : 1.0.0-beta.7+canary.b45e23ba

Application Adapter is set to this:

export default DS.RESTAdapter.extend({
  host: 'http://example.com',
  namespace: 'api/v2',
  headers: {
    "ClientId": "a-key",
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Headers": "X-Requested-With"
  }
});

The locations route looks like this:

export default Ember.Route.extend({
  model: function(params){
    return this.store.find('restaurant');
  }
});

The locations controller looks like this

export default Ember.ArrayController.extend({

  queryParams: ['lat', 'lon', 'limit'],

  lat: null,
  lon: null,
  limit: null,

});

Navigating to this url http://example.com/locations?lat=47.620508&limit=22&lon=-122.349174 Ember data sends http://example.com/locations as the request.

I must be missing something?

Community
  • 1
  • 1
kiwiupover
  • 1,782
  • 12
  • 26

1 Answers1

5

There are a few things you need to do to get query-params-new working as expected.

First, you say you're using the latest ember, but don't specify whether it's the latest stable release or the latest canary release (master). In order to use query-params-new, you need to use canary, which is just the master branch. It is not available in the stable or beta releases yet, but you can download it here.

Second, you need to specify in your controller which params you want to bind to the route. Your locations controller would need to look something like this:

export default Ember.ArrayController.extend({
  queryParams: ['lat', 'lon', 'limit']
});

All of this is documented on the Ember site. http://emberjs.com/guides/routing/query-params/

Edit based on additional question info:

It looks like you're not using the params in your route. You can use findQuery to send the params to the server like so:

export default Ember.Route.extend({
  model: function(params){
    return this.store.findQuery('restaurant', params);
  }
});
Peter Brown
  • 50,956
  • 18
  • 113
  • 146
  • Thanks for the answer I am using Ember: 1.6.0-beta.1+canary.b5b90241 ember.js and Ember Data : 1.0.0-beta.7+canary.b45e23ba and my controller looks like this. I will update the question with the controller. – kiwiupover Mar 01 '14 at 20:16
  • @kiwiupover I updated my answer with another suggestion based on your updated question. I decided to leave the original suggestions in place in case someone else comes across this. – Peter Brown Mar 01 '14 at 20:53
  • Thank you beerlington! The problem was I was not parsing in the params to the route. Also the route could read `return this.store.find('locations', params)`. – kiwiupover Mar 02 '14 at 00:02