jhsu
June 1, 2014, 3:42am
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!
I am not sure if this an option for you, but here is one way to solve it Ember Latest - JSFiddle - Code Playground
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');
}
}
});
jhsu
June 1, 2014, 5:34pm
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!
jhsu
June 3, 2014, 5:08am
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.
https://github.com/emberjs/ember.js/blob/4c3c4db2bba964ece82a01a0fa6127ad60de72ec/packages/router/lib/main.js#L1178-L1226