Skip to content

Instantly share code, notes, and snippets.

@ultimatemonty
Created September 23, 2014 14:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ultimatemonty/c03ac7ed3e953016544f to your computer and use it in GitHub Desktop.
Save ultimatemonty/c03ac7ed3e953016544f to your computer and use it in GitHub Desktop.
Ember CRUD pattern
App.PostsController = Em.ArrayController.extend({
actions: {
create: function () {
// some validation logic here
return this.send('createPost');
},
save: function (model) {
// some validation logic here
return this.send('savePost');
},
delete: function (model) {
// some validation logic here
return this.send('deletePost');
}
}
});
App.PostsRoute = Em.Route.extend({
actions: {
createPost: function () {
var post = store.createRecord( /* stuff here */ );
post.save().then(function (result) {
// some sucecss handling
}, function(error) {
// some error handling
});
},
savePost: function(model) {
model.save().then(function (result) {
// some sucecss handling
}, function(error) {
// some error handling
});
},
deletePost: function(model) {
model.deleteRecord();
model.save().then(function (result) {
// some sucecss handling
}, function(error) {
// some error handling
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment