1

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.

4

1 回答 1

2

事实证明,正如我们大多数人所知,Ember-Rails 预编译了所有这些文件,而您却没有看到它(使用我认为是 Barber gem)。我没有想到的是,当它组合所有这些文件时,它(据我所知)将它们按字母顺序排列。因此, myAdminRoute被声明为扩展AuthenticateRoute之前AuthenticateRoute甚至被声明,从而产生错误。我还不确定如何解决这个问题——

  • 一个天真的解决方法是简单地将文件名从 更改admin_route.jszadmin_route.js,所以它出现在 之后authenticate_route.js,尽管出于明显的原因这并不可取。
  • 或者,也可以通过关闭标志来关闭 Ember-Rails 中的预编译。(见此

如果有人有更好的选择,请在下面发表评论,否则我会在遇到解决方案时更新。

于 2014-06-16T20:22:06.463 回答