Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  72] [ 3]  / answers: 1 / hits: 5688  / 10 Years ago, sun, february 16, 2014, 12:00:00

I'm new to ember and am building a very simple app. I can navigate from my breeders index page(/breeders) to my breeders show page(/breeders/:breeder_id) by clicking on the link generated by the link-to tag. However if I manually navigate to breeders/1 or any of other breeders.show routes I get the following error:



Error while loading route: ReferenceError: params is not defined
at Catapp.BreedersShowRoute.Ember.Route.extend.model


I can't figure out what I've done that is causing this.



This is what I think is the relevant code:



    //router.js
Catapp.Router.map(function() {
this.resource('breeders', function() {
this.route('new');
this.route('show', {path: '/:breeder_id'});
});
});

Catapp.IndexRoute = Ember.Route.extend({
redirect: function(){
this.transitionTo('breeders.index');
}
});

Catapp.BreedersIndexRoute = Ember.Route.extend({
model: function(){
return this.store.find('breeder');
}
});

Catapp.BreedersShowRoute = Ember.Route.extend({
model: function(){
return this.store.find('breeder', params.breeder_id);
}
});


.



// breeders_controller.js
Catapp.BreedersController = Ember.ArrayController.extend({
sortProperties: ['id']
});

More From » function

 Answers
3

You'll need to actually add the argument to the model hook



Catapp.BreedersShowRoute = Ember.Route.extend({
model: function(params){
return this.store.find('breeder', params.breeder_id);
}
});


You can call it whatever you like as well



Catapp.BreedersShowRoute = Ember.Route.extend({
model: function(foo){
return this.store.find('breeder', foo.breeder_id);
}
});

[#47675] Saturday, February 15, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
clarissakourtneyb

Total Points: 710
Total Questions: 89
Total Answers: 125

Location: Dominica
Member since Sat, Nov 5, 2022
2 Years ago
;