1
votes

I have the following controller and I'd like to bubble up an event using send

App.PersonController = Ember.ObjectController.extend({
  page: function(page) {
    var model = PersonApp.Page.create({id: page});
    this.send("person.page", model); //should bubble up ...
  }
});

here is my route setup

PersonApp.Router.map(function(match) {
    this.resource("person", { path: "/" }, function() {
        this.route("page", { path: "/page/:page_id" });
    }); 
}); 

here is the simple page model (shim basically)

PersonApp.Page = Ember.Object.extend({                                                                                                 
});

although I'm using the route "person.page" and I'm passing a valid model I get the following error (seemingly the router does not have this route?)

Uncaught Error: Nothing handled the event 'person.page'.

If it helps debug the controller / router relationship I noticed inside my controller if I dump this.get('target') ...

_debugContainerKey: "router:main"

and if I dig further ... and print this

this.get('target').get('router')

I see a router w/ my route under the currentHandlerInfos array ... not sure if I should be this deep though

... another slight update

If I do this (full blown) it seems to modify the window.location but my model/setupController hooks on the route are never hit

this.get('target').get('router').transitionTo(route, model);

1

1 Answers

3
votes

I think, send is just used for events of a route. Assuming your controller would call send like this:

//in the controller
this.send("personPage", model);

// a matching Route
App.PersonRoute = Ember.Route.extend({
  events : {
    personPage : function(page){
      // this should be called 
    }
  }
});

For your case you need to leverage transitionTo (your access on the router property was too much, i think. The router instance of Ember.Router has again a router property. Pretty confusing :-)).

this.get("target").transitionTo("person.page", model);