0
votes

I'm Using ember 1.13.8 and rails 4 in back-end. I'm having an 'item' model in my app. How can i force ember to reload items route which contains all the items collection after inserting an item record.Here are my route files for items and create:

app/routes/items/create.js
import Ember from 'ember';

export default Ember.Route.extend({
    model: function(){
       return this.store.createRecord('item');
    },
    actions: {
      create: function(){
         var self=this;
         self.controller.get('model').save().then(
            function() {
                self.transitionTo('items');
         });
      }     
    }
});

app/routes/items.js
import Ember from 'ember';

export default Ember.Route.extend({
    model: function(){
        return this.store.findAll('item');
    }
});

After inserting a record, i'm using transitionTo to go to the items route which does not automatically reloads the model, so how can i make ember to reload data from server.

1
Your new "item" record is not added to the "items" list ?kris
The item gets added to the "items" list, but doesn't show up in the "items" list until i refresh the "items" route manually.Dhaval Purohit
store.findAll('item', { reload: true }); //enforces getting fresh datakris
But the model hook doesn't get called on transitionTo the route. It works when i used it as an action, but i want to use it as a hook that gets automatically called on transitionTo.Dhaval Purohit
You newly created item should be already in the store if u wish you can unload items or call the refers..Dory Zidon

1 Answers

0
votes

Try one of the following :

  1. call reset() on the controller instance or
  2. call refresh() on the router instance.
  3. call model.reload()

That should reload the model for you :)