Emberjs linkTo doesnot update collection i.e department.find()

143 Views Asked by At

Learning emberjs
I am not sure if this is a stackoverflow question or git issue. So I decided to put it on stackoverflow first.

Here is my Jsbin (Open in firefox ..not in chrome as raw.github file is used)

When I click on "<- All Department" in department template which I reached after creating a new department it does navigate back to departments template but the #each does not display the newly added department name in list.

It does show the newly added department on refreshing the browser on /departments

1

There are 1 best solutions below

3
scotta7exander On BEST ANSWER

UPDATE

It seems that the .set() method is working but for some reason the new object created is returning the name and ID as undefined. Might be a bug with ember-model perhaps.

The best solution for the moment would be to have 2 save methods, one on the edit controller as you currently do and then adding a different save method for creating a new department.

App.NewController = Ember.ObjectController.extend({
   save:function(){
      var newDep = App.Department.create({name: this.get('name')});
      newDep.save();
      this.get('target').transitionTo('department', this.get('model'));
   }
});

Here is a jsbin with the New controller added - http://jsbin.com/EVUlOyo/1/edit

End Update

It looks like when you are creating the record it is not setting the name value correctly on the object.

I changed the following -

newDepartment = self.get('model');
newDepartment.set('name',this.get('name'));
newDepartment.save();

to -

var newDep = App.Department.create({name: this.get('name')});
newDep.save();

Here is an updated jsbin also http://jsbin.com/EkEXInO/1/edit

Hope that helps and works for you.