0

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

Rigel
  • 882
  • 1
  • 11
  • 32

1 Answers1

0

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.

scotta7exander
  • 383
  • 4
  • 11
  • Hi scotta7exander. Thanks for looking into the problem.But this is not the right solution for it as when u add first Department things are fine. when you add sendon one It will show previous department populated in textbox. and i cannot edit a department in this case same as my jsbin issue – Rigel Sep 04 '13 at 17:27
  • @Rigel - I have updated my answer slightly so that it will work for new and editing. I had a proper look and the .set() is working because I can get those values back from the object but for some reason both the name and id seems to be undefined. Very strange it might be a ember-model bug perhaps. – scotta7exander Sep 04 '13 at 20:48
  • I guess you forgot to paste your updated anwer. In any case I a new to javascript MVC so I am not sure if this issue should goto ember Model github issue list – Rigel Sep 05 '13 at 03:19