I want to access the current user's information on an account page so it can be edited. I wasn't sure how to fetch the current user, so I set up a route on my server called session.
Accessing '/session' on my server returns a JSON blob, { session: {id: "<guid>"}}
, which is the id of the current user in session.
In my ApplicationRoute
, I fetch the id, fetch the corresponding user model, and then set the model as the currentUser
property on my ApplicationController
.
App.ApplicationRoute = Ember.Route.extend({
setupController: function (controller) {
var self = this;
$.getJSON('/session', function (data) {
if (data && data.session && data.session.id) {
self.set('controller.currentUser', self.store.find('user', data.session.id));
}
});
}
});
I'm able to access string properties belonging to the currentUser
from inside the index template after setting up the IndexController
like so:
App.IndexController = Ember.Controller.extend({
needs: ['application'],
currentUser: function () {
return this.get('controllers.application.currentUser');
}.property('controllers.application.currentUser')
});
That's great, but when I try to set up a multiple value Ember.Select, I get this error:
Assertion Failed: Cannot delegate set('roles', []) to the 'content' property of object proxy <DS.PromiseObject:ember435>: its 'content' is undefined.
I made a jsbin
It demonstrates what I'm trying to do. I'm very confident my error is related to the ajax request, getJSON
, because my jsbin example works with localstorage.
How should I be loading the current user? Thanks!