Created
April 28, 2016 14:42
-
-
Save paulcook/c5c201ffcdc938976b2153b68fe3fb52 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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