Skip to content

Instantly share code, notes, and snippets.

@gbabiars
Created August 11, 2013 04:21
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 gbabiars/6203371 to your computer and use it in GitHub Desktop.
Save gbabiars/6203371 to your computer and use it in GitHub Desktop.
An example of the overrides needed to use camel case routes and json.
App.Serializer = DS.RESTSerializer.extend({
keyForAttributeName: function(type, name) {
return name;
},
keyForBelongsTo: function(type, name) {
var key = this.keyForAttributeName(type, name);
if (this.embeddedType(type, name)) {
return key;
}
return key + "Id";
},
keyForHasMany: function(type, name) {
var key = this.keyForAttributeName(type, name);
if (this.embeddedType(type, name)) {
return key;
}
return this.singularize(key) + "Ids";
},
keyForPolymorphicType: function(key) {
return key.replace(/Id$/, 'Type');
},
rootForType: function(type) {
var typeString = type.toString();
Ember.assert("Your model must not be anonymous. It was " + type, typeString.charAt(0) !== '(');
// use the last part of the name as the URL
var parts = typeString.split(".");
var name = parts[parts.length - 1];
return name.charAt(0).toLowerCase() + name.slice(1);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment