mardi 29 septembre 2015

Index model not updating after saving nested model

I'm not sure if maybe I'm doing this wrong in ember, or if I have my structure wrong, or if there is something else I need to implement here, but after editing a nested model from the parent index model it's not updating to reflect the changes in the parent route.

My routes are set up as so

this.route('followers', function() {
  this.route('new');
  this.route('edit', { path: 'edit/:follower_id'});
});

I have a templates/followers/index.hbs

{{#each model as |follower|}}
    ...
{{/each}}

And then I have a link in each model that links to the edit route

{{#link-to "followers.edit" follower.id}}<span class="glyphicon glyphicon-cog edit-action" aria-hidden="true"></span>{{/link-to}}

And in my templates/followers/edit I have a form

<form {{action "editFollower" on="submit"}}>
  <div class="form-group">
    <label for="username">Username</label>
    {{input value=model.username name="username" class="form-control" placeholder="Username"}}
  </div>
  <div class="form-group">
    <label for="minutes">Minutes</label>
    {{input value=model.minutes name="minutes" class="form-control" placeholder="Minutes"}}
  </div>
  <div class="form-group">
    <label for="currency">Currency</label>
    {{input value=model.currency name="currency" class="form-control" placeholder="Currency"}}
  </div>
  <button type="submit" class="btn btn-default">Submit</button>
</form>

This calls an action on my controller controllers/followers/edit

editFollower: function(defer) {
    var self = this;
  var follower = self.get('model');
  follower.save().then(function(){
    self.get('notify').success('Follower edited');
    self.transitionToRoute('followers.index');
  }).catch(function(){
    alert('there was a problem');
  });
}

This all works up to this point however after transitioning back to the index route I have to refresh and hit the API again to see the changes that the edit action made. Is this not possible with my current pattern or did I just set it up wrong?




Aucun commentaire:

Enregistrer un commentaire