I have the following Ember adapter for a model called time-zone
:
import Ember from 'ember';
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
namespace: 'api/v2',
pathForType: function(type) {
// type here is "time-zone"
return Ember.String.underscore(type);
}
});
What I want is for my HTTP request to be sent to /api/v2/time_zones
, but it's coming through as /api/v2/time_zone
, which is wrong.
This is my model file:
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string')
});
And this is the relevant part of my routing file:
import Ember from 'ember';
export default Ember.Route.extend({
model(params) {
return Ember.RSVP.hash({
timeZones: this.store.findAll('time-zone')
});
}
});
Adapting a name like timeZone
or time-zone
to an endpoint URI like /api/v2/time_zones
seems like an extremely common use case for Ember, so I'm perplexed at the fact that what I'm trying isn't working.
I can do this and make it work:
return Ember.String.pluralize(Ember.String.underscore(type));
But that seems like a silly hack for what again must be a super common use case.
Aucun commentaire:
Enregistrer un commentaire