Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js: how to save a model

From the ember docs its clear you should be able to save a dirty model

var m = App.MyModel.find(10) ;
...
m.set("firstName", "John") ;
m.get("isDirty") ; // --> true

Now, I don't know how to save, things like

m.save() ;
App.MyModel.save(m) ;
//etc

do not work. Any suggestions ?

CHeers

like image 628
Jeanluca Scaljeri Avatar asked Jan 22 '13 09:01

Jeanluca Scaljeri


1 Answers

The accepted answer is no longer valid since the release of Ember Data 1.0 (beta at the time of writing). Saving is much easier and more intuitive with Ember Data (1.0).

var person = this.store.createRecord('person');
person.set('frist_name', 'John');
person.set('last_name', 'Doe');
person.save();

It is also good to know that a save call returns a promise, which is resolved when the server returns a response.

person.save().then(function() {
  // SUCCESS
}, function() {
  // FAILURE
});
like image 159
Bart Jacobs Avatar answered Nov 14 '22 19:11

Bart Jacobs