Created
September 23, 2014 14:31
-
-
Save ultimatemonty/c03ac7ed3e953016544f to your computer and use it in GitHub Desktop.
Ember CRUD pattern
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
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