Ember can't access the controllers scope in a didLoad callback when testing with Konacha


This code works perfectly on my browser:

doLogin: (user) ->
  _controllers = @get('controllers')

  res = Cluey.Order.find({table: null, user: user.get('id')})

  res.on 'didLoad', =>
    order = @objectAt(0)
    console.log _controllers
    _controllers.get('order').set('model', order)

But when it runs under Konacha when I’m testing my app it throws this weird output:

Hi, we are the controllers !  users_controller.js:95

Class {controller: Class, toString: function, constructor: function, controller: null, unknownProperty: function…} users_controller.js:96

Uncaught Error: assertion failed: calling set on destroyed object 

How is that possible ?

Same issue on SO


_controllers is set before your didLoad callback is defined, so I think your question title is incorrect (and you don’t seem to have a complete understanding of JavaScript). Your problem is not that you can’t access controllers inside your didLoad handler.

Your output does not show the result of console.log’ing _controllers. I don’t think it went into the didLoad handler at all.

Your code stopped somewhere after it executed line 96 in users_controller.js, but you really need to set breakpoints or place console.log or use the debugger to figure out where. You’ll find better help here if you do more on your own to narrow down the problem.