Moving the route model
I have an app with a shopping cart displayed at the top of the page in my app template. Then, in the application route, I define the model line by line:
App.ApplicationRoute = Em.Route.extend
model: (->
@store.find('cart', @session.get('cart_id')
).observes('session.cart_id')
When the user logs in, I want to replace this bucket with the one downloaded from the server. What is the best way to approach this?
I got to the point where the cart is loaded into the Ember Data store, the watcher block starts, but the template is not updated with the new model. Or maybe I should be using something completely different for this?
source to share
the model hook is called by the router when connecting models for the current route. If you want to change the model on the controller, just take the controller and set the property to a model
new model.
Assuming the session exists in the app route
App.ApplicationRoute = Em.Route.extend
updateModel: (->
@store.find('cart', @session.get('cart_id')).then (record) =>
@controller.set('model', record)
).observes('session.cart_id')
(I have mixed and matched coffeescript, I only know this from stackoverflow questions, so sorry if this is not the case)
source to share