I'm in the process of transitioning a standard Rails app over to an Ember app with Rails API. This is an incremental process so for the short term users will be switching back and forth between the newer parts of the site (using Ember) and the old legacy views.
At one point, in the ember app, the user creates a new 'Plan' model
plans/new.hbs
<button {{action createNewPlan}}>Create Plan</button>
After the plan has been successfully created, I want to transition to plan/show view ON THE OLD Rails app.
I've defined the createNewPlan action in the plans_new_router, rather than the controller, as I understand the router should be responsible to tracking application state.
plans_new_router.js
App.PlansNewRoute = Ember.Route.extend({
events: {
createNewPlan: function() {
var newPlan = this.controllerFor('plans_new').get('content');
newPlan.get('transaction').commit();
// how can I transition to plans/show in the old rails app ????
}
}
}
I'd like to transitionTo the plans_show view on the old rails app after the model has been saved. How can I do this? transitionTo requires an ember route, I take it. But what I want to do is reset the brownser to the appropriate rails URL with the new plan id. I'm guessing transitionTo isn't what I want to use.
How do I do it?
window.location =
maybe? You probably want to wait until the response though? If you do, I think ember-data is becoming promise-based really soon, or master might already be, not too sure.
If it's not yet, you can addObserver
to the id
property of newPlan
and when it changes, set the window.location