Created
June 19, 2015 23:18
-
-
Save codeithuman/6c3aec1528a0bff6bc99 to your computer and use it in GitHub Desktop.
try catch on saving ember object
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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
needs: ['question'], | |
actions: { | |
addAnswer: function() { | |
var self = this; | |
var newAnswer = self.store.createRecord('answer', { | |
author: self.get('author'), | |
date: new Date(), | |
body: self.get('body') | |
}); | |
newAnswer.save().then(function(answer){ | |
var currentQuestion = self.get('controllers.question.model'); | |
currentQuestion.get('answers').pushObject(answer); | |
currentQuestion.save().then(function(q){ | |
self.transitionToRoute('question', currentQuestion.id) | |
self.setProperties({ | |
author: '', | |
date: '', | |
body: '' | |
}); | |
}).catch(function(e){ | |
console.log('Question did not save.'); //TODO: Handle error properly | |
}); | |
}).catch(function(e){ | |
console.log('answer did not save.'); //TODO: Handle error properly | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment