mercredi 30 septembre 2015

User ActiveModelAdapter to make arbitrary JSON query in ember

I'm using the standard ActiveModelAdapter in my Ember app to do most of my queries to work with Ember model object.

In one case, however, I want to make a arbitrary REST request to get back JSON to populate a chart (not backed by a model) but I want to go "through" the ActiveModelAdapter so the correct host values are used.

Here's what's not working:

updateChartFromIndustry: function() {
  Ember.$.ajax({
    context: this,
    method: 'get',
    url: 'api/v3/charts/all_risk.json',
    dataType: 'json',
    data: { ind: this.get('ind') }
  }).then(function(json) {
      Ember.$('#risk-days-data').highcharts(json);
    },
    function(errs) {
      console.log(errs);
    }
  );
}.observes('ind'),

In development, that query goes to localhost:4200 (the ember server) rather than the rails backend at localhost:3000. Explicitely setting the full URL makes the query go through but without the various user session informatino that authenticates the request.

I'm really hoping for something simple like:

this.store.query('arbitrary url and params', ....)

as if I were making a normal query for a model or, alternately, to leverage the adapter:

Ember.adapter.$.ajax(....) 




Aucun commentaire:

Enregistrer un commentaire