简体   繁体   中英

Ember-Rails “Cannot read property 'extend' of undefined”

I'm using Ember-Rails to build an Ember front-end app with a Rails API for a beckend. I've been working on implementing authentication, and I arrived at the following error: Cannot read property 'extend' of undefined when trying to extend a route as follows:

App.AdminRoute = App.AuthenticateRoute.extend({
    model: function(params) {
        return this.store.find('user', params.id);
    },
});

And I had an AuthenticateRoute defined as follows:

App.AuthenticateRoute = Ember.Route.extend({
    //yada yada
});

I was more-or-less following a guide found on: http://www.embercasts.com/episodes/client-side-authentication-part-2

I am not sure why this is not working, but I noticed my AuthenticateRoute could be extended from other routes, which I find extremely strange.

Turns out that, as most of us know, Ember-Rails precompiles all these files without you seeing it (using what I believe is the Barber gem). What I didn't think about is that, when it combines all these files, it (as far as I can tell) puts them in alphabetical order. As such, my AdminRoute was being declared as extending AuthenticateRoute before AuthenticateRoute was even declared, thus producing the error. I'm not yet sure how to solve this--

  • A naive fix is to simply change the filename from admin_route.js to zadmin_route.js , so it comes after authenticate_route.js , though this isn't desirable for obvious reasons.
  • Alternatively, it is also possible to turn precompiling in Ember-Rails off by setting a flag off. (see this )

If anyone has a superior alternative, please comment below, else I will update this when I come across a solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM