createRecord (store, type, snapshot) Promise
Implement this method in a subclass to handle the creation of new records.
Serializes the record and sends it to the server.
Example
app/adapters/application.js
import DS from 'ember-data'; export default DS.Adapter.extend({ createRecord: function(store, type, snapshot) { var data = this.serialize(snapshot, { includeId: true }); return new Ember.RSVP.Promise(function(resolve, reject) { Ember.$.ajax({ type: 'POST', url: `/${type.modelName}`, dataType: 'json', data: data }).then(function(data) { Ember.run(null, resolve, data); }, function(jqXHR) { jqXHR.then = null; // tame jQuery's ill mannered promises Ember.run(null, reject, jqXHR); }); }); } });
Parameters:
-
store
DS.Store
-
type
DS.Model
- the DS.Model class of the record
-
snapshot
DS.Snapshot
Returns:
-
Promise
- promise
Please login to continue.