Skip to content

Instantly share code, notes, and snippets.

@paulcook
Created April 28, 2016 14:42
Show Gist options
  • Save paulcook/c5c201ffcdc938976b2153b68fe3fb52 to your computer and use it in GitHub Desktop.
Save paulcook/c5c201ffcdc938976b2153b68fe3fb52 to your computer and use it in GitHub Desktop.
// Shopmaster/frontend/app/routes/grocery-lists/new.js
import Ember from 'ember';
export default Ember.Route.extend({
setupController: function(controller, model) {
controller.set('model', model);
},
model: function() {
return this.store.createRecord('grocery-list');
},
actions: {
save: function() {
var model = this.get('controller.model');
var _this = this;
var promises = [];
model.save().then(function(groceryList){
groceryList.get('items').forEach(function(item) {
promises.push(item.save());
});
return Ember.RSVP.all(promises).then(function () {
_this.transitionTo('grocery-lists.index');
}).catch(function () {
console.log('one of the saves failed');
});
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment