0

I have a Host model on ember-data:

App.Host = DS.Model.extend
  name: DS.attr 'string'

And I using the DS.RESTAdapter.

EmberJS calls /hosts to get hosts which is normal.

My problem is the url to get hosts is not /hosts but /nagios/hosts.

How can I specify this url only for Host model?

I already tried those answers:

Without any success.

Currently using:

Ember      : 1.10.0
Ember Data : 1.0.0-beta.15
jQuery     : 2.0.3

Thanks for help.

3 Answers 3

3

Add an adapter (ember generate adapter hosts) just for the hosts model and add the namespace property:

App.HostsAdapter = DS.RESTAdapter.extend({
  namespace: 'nagios'
});
Sign up to request clarification or add additional context in comments.

7 Comments

Where should I put this by convention? On my model file?
If you are using Ember CLI you could use the ember generator like: ember generate adapter hosts and it will generate a folder called "hosts.js" in "adapters". So the full path is .../app/adapters/hosts.js
I'm not using Ember CLI. I tested your solution, did nothing. What could I did wrong?
You could try to name it: App.HostAdapter instead of App.HostsAdapter, but make sure that this code is somewhere included or create an own file like hosts-adapter.js and include it.
Here are the docs for further reading: emberjs.com/guides/models/the-rest-adapter It is definitely possible to create an adapter for a single model by just following the naming conventions.
|
1

Finally found the correct solution.

For begin by the context, I have an initial RESTAdapter config:

App.ApplicationAdapter = DS.RESTAdapter.extend
  host: 'http://localhost:8000/api'

To add the /nagios url part, just create a file named adapters/host.coffee (or .js) like this:

App.HostAdapter = App.ApplicationAdapter.extend
  namespace: 'nagios'

Please not App.ApplicationAdapter extension instead of DS.RESTAdapter in order to keep the initial configuration.

And voila! The called url is now http://localhost:8000/api/nagios/hosts.

Thanks a lot to EntspAndi for the very useful help!

Comments

0

namespace for setting a path in same directory

App.HostsAdapter = DS.RESTAdapter.extend({namespace: 'nagios' });

Or

host generally is used for changing the directory

App.HostsAdapter = DS.RESTAdapter.extend({ host: 'nagios' });

In case you want to add suffix to the file name do it this way (place this inside extend()).

suffix: '.json',

      pathForType: function(type) {
        return this._super(type) + this.get('suffix');
      }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.