0

I'm trying to wrangle my way through my first Ember.js app, and am struggling to figure out how to take my boilerplate/tutorial-based code and get it to pass parameters through to my Flask backend.

I want to serve up local events based on zip code, with the zip code being passed through to the backend.

I came across this page on Opting into a Full Transition (http://emberjs.com/guides/routing/query-params/#toc_opting-into-a-full-transition) and am now seeing the parameter name but not the value coming through the request to the API.

I visit this URL in my browser: http://localhost:5000/?zip=21210

and I get:

127.0.0.1 - - [22/Dec/2014 23:20:51] "GET /?zip=21210 HTTP/1.1" 200 - # first call to load page
127.0.0.1 - - [22/Dec/2014 23:20:52] "GET /api/v1/events?zip= HTTP/1.1" 200 - # call to API

my app.js file:

App = Ember.Application.create();

App.Router.map(function() {
    location: 'auto'
  // put your routes here
  //this.resource('events', {path: '/'})
});

//var attr = DS.attr;

DS.RESTAdapter.reopen({
  namespace: 'api/v1'
});

App.Event = DS.Model.extend({
    name: DS.attr('string'),
    address: DS.attr('string')
});


App.IndexRoute = Ember.Route.extend({
    queryParams: {
        zip: {
            refreshModel: true
        }
    },
  model: function(params) {
    return this.store.findQuery('event', params);
  }
});

App.IndexController = Ember.ArrayController.extend({
    queryParams: ['zip'],
    zip: null
});
jwoww
  • 991
  • 1
  • 11
  • 19

1 Answers1

1

queryParams binds zip to the property zip in your controller which is null. This is why you are seeing an empty zip parameter being passed in to the server.

Make sure to assign a non-null value to zip property and you will stop seeing zip parameter being empty.

Kalman
  • 8,001
  • 1
  • 27
  • 45
  • Thanks. This put me on the right track. I didn't realize that the documentation was written around watching changes to parameters AFTER the app loads, and setting zip to NULL happens when the app loads. I used some simple code to grab the parameter from the URL (http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter) and set zip to QueryString.zip in the controller. Now it's all good. Would you like to update your answer with more details and I will accept it? – jwoww Dec 23 '14 at 17:56
  • I edited my answer. Not sure if it gets the point across any better, but I tried rephrasing it. – Kalman Dec 23 '14 at 19:02