transitionToRoute with a new model


#1

I want to initialize a new model and pass with this.transitionToRoute, but it doesn’t seem to transition or throw any errors.

basically:

App.IndexController = Ember.Controller.extend({
  actions: {
    newEvent: function() {
      var model = this.store.createRecord('event', {name: "unsaved event"});
      this.transitionToRoute('events.new', model);
    }
  }
});

here’s a jsbin showing what I want to do: http://emberjs.jsbin.com/dunak/1/edit. Am I supposed to do something with serialize on the EventsNewRoute?

Thanks!


#2

I am not sure if this an option for you, but here is one way to solve it http://jsfiddle.net/NQKvy/1015/


#3

Since you’ve defined events/new as route and not as a resource, you could create the model in the model hook of your EventsNewRoute:

App.EventsNewRoute = Ember.Route.extend({
    model: function() {
        return this.store.createRecord('event', { name: "unsaved event"});
    }
});

and simply transition to the new route without passing the model:

App.IndexController = Ember.Controller.extend({
   actions: {
      newEvent: function() {
          this.transitionToRoute('events.new');
      }
   }
});

#4

@splattne the thing is, the model properties need to come from the controller that’s calling this.transitionToRoute so putting it in the EventsNewController wont’ work. Thanks though!


#5

After a bit of deep diving, it appears the router expects either a dynamic segment to be in the url or it treats the objects as query params, which seems incorrect to me.