I am trying to send data from my front end ember app to a rails API. The method in question, donate, sits at a custom route:
patch 'accounts/:id/donate' => 'accounts#donate'
In order to call to it, I understand that my ember route needs to use an adapter to override the normal patch methods, but that is about where my knowledge ends. This is the state of my current route:
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
donate(params){
console.log('hits');
console.log(params);
let patron = this.get('store').findRecord('account', 10);
// here is where I need to link to my adapter
patron.donate(params);
}
}
});
and my adapter file (I cannot even get this to fire yet, so the low quality of the code is to be expected):
import ApplicationAdapter from './application';
export default ApplicationAdapter.extend({
// Not super confident about this adapter, not am I super confident about how I
// am passing data through it.
donate(store, type, record) {
let api = this.get('host');
let serialized = this.serialize(record, {includeId: true});
let accountId = serialized.account_id;
let url = `${api}/accounts/${accountId}/donate`;
let data = {account: serialized};
return this.ajax(url, 'PATCH', {data});
}
});
The first step to getting this functionality working is making sure my adapter can properly call to my server. How/where would I go about making this happen?
Aucun commentaire:
Enregistrer un commentaire