Created
February 10, 2014 15:49
-
-
Save HeroicEric/8918269 to your computer and use it in GitHub Desktop.
Ember data nested URL
This file contains 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
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('/'); | |
} | |
}); |
This file contains 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
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