Chris
Chris

Reputation: 824

Ember.js: How to sync model to a different namespace from the default

In my store.js.coffee, I'm setting the namespace for my API:

DS.RESTAdapter.reopen
  namespace: "api/v1"

That's the base namespace I want to use for my ember-data API calls to Rails Active Model Serializers.

But in some API calls, I want my model to sync with an endpoint in the namespace api/v1/admin.

How do I do this in Ember (leaving the application default as api/v1)?

Upvotes: 2

Views: 1139

Answers (2)

blimmer
blimmer

Reputation: 2486

The previous answer here is actually no longer valid (as of Ember Data 1.0.beta.1).

Per the changelog, you now use the ModelNameAdapter syntax. For example,

App.AdminAsset = DS.Model.extend({
    ...
});

App.AdminAdapter = DS.Adapter.create({
    url: 'api/v1/admin'
    ...
});

App.AdminAssetAdapter = App.AdminAdapter;

Upvotes: 1

buuda
buuda

Reputation: 1427

You can set adapters per type in ember. So create another adapter for '/admin', set the namespace on that adapter to "api/v1/admin" and then set the appropriate types to use that adapter instead:

App.AdminAsset = DS.Model.extend({
   ....
});

App.adminAdapter = DS.Adapter.create({
    url: "api/v1/admin"
});


App.Store.registerAdapter(App.AdminAsset, App.adminAdapter);

Upvotes: 2

Related Questions