Skip to content

Commit

Permalink
Make path optional
Browse files Browse the repository at this point in the history
When using ember-api-actions with ember-data-url-templates, you can pass
a `urlType` to `memberAction` and then define a template specifically for your
new `urlType`. For example:

    // model
    ripen: memberAction({ urlType: 'ripen' }),

    // adapter
    ripenTemplate: '/fruits/{id}/ripen.json',

However, this breaks down when adding a path.
  • Loading branch information
Amiel Martin committed Sep 8, 2016
1 parent ac2afb9 commit 4ac52a3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions addon/utils/build-url.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import Ember from 'ember';

const { assert } = Ember;

export function buildOperationUrl(record, opPath, urlType, instance=true) {
assert('You must provide a path for instanceOp', opPath);
let modelName = record.constructor.modelName || record.constructor.typeKey;
let adapter = record.store.adapterFor(modelName);
let path = opPath;
let snapshot = record._createSnapshot();
let baseUrl = adapter.buildURL(modelName, instance ? record.get('id') : null, snapshot, urlType);

if (baseUrl.charAt(baseUrl.length - 1) === '/') {
return `${baseUrl}${path}`;
if (path) {
if (baseUrl.charAt(baseUrl.length - 1) === '/') {
return `${baseUrl}${path}`;
} else {
return `${baseUrl}/${path}`;
}
} else {
return `${baseUrl}/${path}`;
return baseUrl;
}
}

Expand Down

0 comments on commit 4ac52a3

Please sign in to comment.