Skip to content

Instantly share code, notes, and snippets.

@rwjblue
Created March 5, 2014 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwjblue/9359366 to your computer and use it in GitHub Desktop.
Save rwjblue/9359366 to your computer and use it in GitHub Desktop.
Custom Model Specific Adapters
// So you likely have an application adapter like so:
App.ApplicationAdapter = DS.ActiveModelAdapter.extend(); // could also be REST adapter
// And you have a model:
App.Comment = DS.Model.extend({
text: DS.attr(),
createdBy: DS.attr()
});
App.CommentsRoute = Ember.Route.extend({
model: function(){
// by default this will perform a GET request to your API endpoint
this.store.find('comment');
}
});
// BUT you want a POST, so just define a custom adapter for the comment model:
App.CommentAdapter = App.ApplicationAdapter.extend({
// this gets called when you do not pass an ID to this.store.find
findAll: function(store, type) {
return this.ajax(this.buildURL(type.typeKey), 'POST');
},
// this gets called when you do pass an ID
find: function(store, type, id) {
return this.ajax(this.buildURL(type.typeKey, id), 'POST');
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment