我正在开发一个Rails4,ember rails,ember source 1.2.0应用程序,使用devise进行身份验证。
我让应用程序成功地发出身份验证请求,接收用户详细信息,现在我需要一个很好的位置来存储整个应用程序中的"current_user“。我试着编写自己的初始化器来做一些注入,但它似乎不是一个有良好文档记录的代码路径:
Admin.initializer({
name: 'currentUser',
initialize: function(container, application){
container.optionsForType('user', { instantiate: false, singleton: true });
application.register('user:current',Admin.User.createRecord({}));
application.inject('route','current_user','user:current')
application.inject('controller','current_user','user:current')
application.inject('view','current_user','user:current')
}
})此代码错误是因为:
Assertion failed: Error while loading route: TypeError: Cannot call method 'set' of undefined如何注册单个模型并使其在整个视图级别都可见?一旦我注册了单例,我将发出一个ajax登录请求并填写它的属性,或者将用户发送到一个登录屏幕。
发布于 2013-11-27 12:51:18
这就是它的工作方式,你的错误发生在其他地方。您需要显示其他信息。
http://emberjs.jsbin.com/esEYIrIR/2/edit
https://stackoverflow.com/questions/20232988
复制相似问题