Hi,
99% of my app uses restful Ember data. But a few actions we want to keep as member routes (for server side reasons).
I’ve looked over other threads, like this, but still not sure ideal way to keep it as Ember-like as possible.
Simple example
ContactRequest model
var ContactRequest = DS.Model.extend({
sender: DS.belongsTo('profile')
});
ContactRequest.reopen({
accept: function () {
var self = this;
return new Em.RSVP.Promise(function (resolve, reject) {
Em.$.post('api/v1/contact_requests/' + self.get('id') + '/accept').done(function () {
resolve();
}).fail(function () {
reject();
});
});
}
});
export default ContactRequest;
controller
export default Em.ObjectController.extend({
actions: {
accept: function () {
this.get('model').accept().then(function () {
// handle success
}, function () {
// handle fail
});
}
}
});
Then I can also loadMany into the store, etc.
This feels clean to me, so I’m fine with it. But is it the best place? Should it instead go in the adapter?
But my biggest question is this goes outside of application adapter. I want to inherit headers for my API, and preferably the host / namespace (api/v1 etc) that I have set up in application adapter.
Any ideas on how to do this the cleanest way possible?