RESTadpater を使用してデータを永続化します。検証エラーが発生した場合、422 応答を返し、エラーをログに記録し、正しくない各フィールドの横に表示を表示したいと考えています。
私の REST 応答ステータス コードは次のとおりです。
Status Code:422 Unprocessable Entity
私の REST 応答本文は次のとおりです。
{
"message": "Validation failed",
"errors": [
{
"name": "duplicate"
}
]
}
私のコントローラーでは、 becomeInvalid が正しく起動します。
App.AuthorsNewController = Ember.ObjectController.extend({
startEditing: function () {
//Create a new record on a local transaction
this.transaction = this.get('store').transaction();
this.set('model', this.transaction.createRecord(App.Author, {}));
},
save: function (author) {
//Local commit - author record goes in Flight state
author.get('transaction').commit();
//If response is success: didCreate fires
//Transition to edit of the new record
author.one('didCreate', this, function () {
this.transitionToRoute('author.edit', author);
});
//If response is 422 (validation problem at server side): becameError fires
author.one('becameInvalid', this, function () {
console.log "Validation problem"
});
}
...
2 つの質問:
「console.log "Validation problem"」の下に、サーバーから返されたエラーの完全なリストを記録したいと思います。どうやってやるの ?
hbs テンプレートで、関連するフィールドの横にエラーを表示したいと考えています。これどうやってするの ?
REST アダプター経由で返されたデータが正しいかどうかはわかりません。したがって、問題はREST側またはEmber側にある可能性があります...