Reputation: 6138
Disclaimer: major newbie warning!
I've successfully set up a Rails backend/Ember front-end project following this tutorial.
My router is
import Ember from 'ember';
import config from './config/environment';
var Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.resource('contacts', function() {
this.resource('contact', { path: '/:contact_id' });
});
});
export default Router;
Now I want to set up the possibility for finding only certain contacts based on the contact's lastName, so I followed the official docs for specifying query params.
I've modified my app/routes/contacts/index.js
route so that it now looks like this:
import Ember from 'ember';
export default Ember.Route.extend({
queryParams: {
lastName: {
refreshModel: true
}
},
model: function(params) {
return this.store.findQuery('contact', params);
}
});
and app/controllers/contacts.js
import Ember from 'ember';
export default Ember.ArrayController.extend({
queryParams: ['lastName'],
lastName: null,
});
Unfortunately, params
isn't filled, even when I specify a query param in the browser. More precisely, the params
object looks like this:
which doesn't seem to contain anything interesting to me.
Yet, the query params information is somehow propagated to the view, so I feel slightly baffled. How can I have params
be filled for the model hook in my route?
Upvotes: 1
Views: 112
Reputation: 6138
It seems as though this might be a bug. A simple work around is accessing the query params through the optional transition param:
import Ember from 'ember';
export default Ember.Route.extend({
queryParams: {
lastName: {
refreshModel: true
}
},
model: function(params, transition) {
return this.store.findQuery('contact', transition.queryParams);
}
});
Upvotes: 1