Call store from within a controller


#1

Hello everyone,

ember newby here. I need to get back some metadata from the server after a PUT request, therefor I want to use the native ember function ‘store.metadataFor()’ within the controller after saving. My code looks like this (coffeescript):

I want to get the value of the key ‘message’ from the metadata. The json form the server is ok (keyname ‘meta’)…however I get the error:

Error: Assertion Failed: TypeError: this.store is undefined

I’m able to access the store from withing routes, but as far I understand the concept it should work from withing a controller too…

Any help would be appreciated, Thank you


#2

I’m not fluent in coffeescript, so this could be off the mark, but if that @store is equivalent to this.store, then you have the problem that ‘this’ is scoped to the global context rather than your controller (if you want I could elaborate on this, but it’s a pretty common javascript quirk). I have written the exact lines of code you have there many times, and always end up with something like

save: function () {
    var that = this;
    this.get('content').save(function () {
        that.get('someControllerProperty');

#3

You are awesome! Saved me, thank you for your quick reply!