Skip to content

Instantly share code, notes, and snippets.

@HeroicEric
Created February 10, 2014 15:49
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 HeroicEric/8918269 to your computer and use it in GitHub Desktop.
Save HeroicEric/8918269 to your computer and use it in GitHub Desktop.
Ember data nested URL
export default DS.ActiveModelAdapter.extend({
namespace: 'api/v<%= Rails.application.config.ember.api_version %>',
buildNestedURL: function(parents, type) {
var _this = this;
var url = Ember.makeArray(parents).map(function(model) {
return _this.buildURL(model.constructor.typeKey, model.get('id'));
});
url.push(this.pathForType(type));
return url.join('/');
}
});
import ApplicationAdapter from "./application";
export default ApplicationAdapter.extend({
createRecord: function(store, type, record) {
var data = {};
var serializer = store.serializerFor(type.typeKey);
var challenge = record.get('challenge');
var url = this.buildNestedURL(challenge, type.typeKey);
serializer.serializeIntoHash(data, type, record, { includeId: true });
return this.ajax(url, "POST", { data: data });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment