Skip to content

Instantly share code, notes, and snippets.

@ugisozols
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugisozols/9684528 to your computer and use it in GitHub Desktop.
Save ugisozols/9684528 to your computer and use it in GitHub Desktop.
Overriding url that's being hit on the backend on a per model basis
// Problem.
//
// I wanted for this.store.find("account") in AccountRoute's model hook to hit /account instead of /accounts so I ended up
// creating App.AccountAdapter where I subclass App.ApplicationAdapter and override pathForType.
// See https://github.com/emberjs/data/blob/v1.0.0-beta.6/packages/activemodel-adapter/lib/system/active_model_adapter.js#L65
//
// Note: In my app I'm using DS.ActiveModelAdapter.
//
// <3 https://github.com/robyurkowski for help.
App.Account = DS.Model.extend({
email: DS.attr("string")
});
App.AccountRoute = Ember.Route.extend({
model: function() {
return this.store.find("account");
}
});
// this makes it so we hit /account instead of /accounts
App.AccountAdapter = App.ApplicationAdapter.extend({
pathForType: function(type) {
var decamelized = Ember.String.decamelize(type);
var underscored = Ember.String.underscore(decamelized);
return underscored;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment