Last active
August 29, 2015 14:07
-
-
Save skinofstars/f7e7dd58460eb11316c7 to your computer and use it in GitHub Desktop.
ember data not populating model errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using ActiveModelAdapter | |
App.ApplicationAdapter = DS.ActiveModelAdapter.extend(); | |
// simple model | |
App.Job = DS.Model.extend({ | |
external_ref: DS.attr("string") | |
}); | |
// creating a new Job. | |
App.JobsNewController = Ember.Controller.extend({ | |
actions: { | |
save: function() { | |
var newJob = this.store.createRecord('job', { | |
'external_ref' : this.external_ref, | |
}); | |
newJob.save().then(function(){ | |
}, function(fail){ | |
// server fails validation, so responds to save with {"errors":{"external_ref":["can't be blank"]}} | |
// InvalidError object | |
console.log(fail) | |
// this is the obj sent from server | |
console.log(fail.errors) | |
// an ember array of length 0 | |
console.log(newJob.get('errors').toArray()) | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment