简体   繁体   中英

Ember-data send request with capital letter

I have a problem with ember-data. I have a model called "optionValue". When I save my model, it will send the following url to my server :

www.myapi.com/optionValues

this doesn't work because of the "V". I would need the request to be all lowercase. Anyone has an idea on how I should proceed? I have tried multiple thing on the back end, but there is nothing to do. Anyway, I don't think that it is ever a good idea to have capital letter in an URL.

Cheers.

it seems like Ember just pluralizes the model name. You can change this by overriding the pathForType function on your adapter (I'm assuming you are using the default RESTAdapter).

    DS.RESTAdapter.reopen({
      pathForType: function(type) {
        var decamelized = Ember.String.decamelize(type);
        return Ember.String.pluralize(decamelized);
      };
    });

Also see the api docs for pathForType : http://emberjs.com/api/data/classes/DS.RESTAdapter.html#method_pathForType

If you're using Rails as a backend it would be wise to use ActiveModelAdapter which includes this behaviour for pathForType amongst other things ;)

I kept digging and finally found the answer to my own questin. The RESTAdapter has a buildUrl method. I simply

DS.RESTAdapter.reopen({
    buildURL: function(record, suffix) {
      return this._super(record,suffix).toLowerCase();
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM