Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember "Params is not defined" in routing

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']
});
like image 668
mrabin Avatar asked Feb 16 '14 16:02

mrabin


1 Answers

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);
    }
});
like image 195
Kingpin2k Avatar answered Oct 20 '22 08:10

Kingpin2k