Asked By: Anonymous
I guess I’m missing something really basic, but the following fails with The action 'login' did not exist on App.AppController
.
Template:
<h2>Click the button and watch the console</h2>
<button type="button" {{action login target="App.AppController"}}>Log in</button>
Controller:
App.AppController = Ember.Controller.extend({
login: function() {
// never gets here
debugger;
},
send: function() {
// or even here
debugger;
}
});
JSBin: http://jsbin.com/okuqiv/5/edit (this is pointing to Ember latest, but it’s the same behavior with 1.0-rc2, the version I’ve been using for a couple of days; I haven’t tried it on previous versions).
Upon debugging, it seems that somehow the controller mixin is not exposing all the functions it should — login() is a function I added, but send() is an Ember function. It’s also missing other functions like get().
I saw that in my app the login() function exists on the object App.AppController.prototype, while in the JSBin it exists on one of the objects in the mixin chain.
At this point I’d even be happy to handle the login action in the view, or the router (as it seems it was the default in the past), but none of those seem to work.
From the documentation, the current default place where the actions handlers should live is the controller anyway, and then the routes, but if I remove the target and add login() to the route, I get another error: Nothing handled the event 'login'
(I’m using the target in the first place because in my app /login is a separate route and has a different controller).
Solutions and workaround will be very appreciated!
Solution
Answered By: Anonymous
You are targeting the class App.AppController and not an actual instance of that class. If you are using the router and are in an app view then action would target the appController by default.
I’ve updated the JSbin to call login on the IndexController since your example is in the index route:
You were also over riding the send method which was preventing login from being called.