Skip to content

Instantly share code, notes, and snippets.

@typeoneerror
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typeoneerror/e5ae6ee4dbde90587aee to your computer and use it in GitHub Desktop.
Save typeoneerror/e5ae6ee4dbde90587aee to your computer and use it in GitHub Desktop.
apiPathFor
import DS from 'ember-data';
export default DS.ActiveModelAdapter.extend({
host: 'http://customhost.dev',
namespace: 'api/v1'
});
DS.Store.reopen({
apiPathFor: function() {
var url = arguments.length ? Array.prototype.slice.call(arguments).join('/') : ''
, adapter = this.adapterFor('application')
return [adapter.urlPrefix(), url].join('/');
}
});
@typeoneerror
Copy link
Author

Use case inside a route (or object with access to DS.Store):

actions: {

  doSomething: function() {
    var param1 = 1;
    var param2 = 'test'
    var url = this.store.apiPathFor('custom/thing', param1, param2);

    // http://customhost.dev/api/v1/custom/thing/1/test
    console.log(url);
  }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment