Reputation: 8255
I'm trying to get a simple REST API setup going with ember, but I can't get it to hit the correct end point, I've tried all sorts with no avail, but my code currently looks like this:
window.App = Ember.Application.create({
LOG_TRANSITIONS: true,
LOG_TRANSITIONS_INTERNAL: true
});
App.ApplicationAdapter = DS.RESTAdapter.extend({
host: 'http://myserver.com'
});
/* Setup routes */
App.Router.map(function() {
this.route("bar");
});
App.BarRoute = Ember.Route.extend({
model: function() {
return this.store.findAll('bar');
}
});
In the main index template I have {{#link-to "bar"}}Bars{{/link-to}}
, yet when I click the link (running the page locally) I see this in the console:
OPTIONS file://localhost/bars
Whatever I try it's always using a relative URL and not prefixing the host as I'm expecting, and if I put a breakpoint in ember_data.js on the line Ember.$.ajax(hash);
I can see that hash.url
is just "/bars". What am I missing here?
Upvotes: 2
Views: 1077
Reputation: 90
Dont forget to set the Adapter to the Store, like this:
App.Adapter = DS.RESTAdapter.extend({
host: 'http://www.yourdomain.com',
namespace: 'url/path/to/app'
});
App.Store = DS.Store.extend({
adapter: App.Adapter
});
Hope it helps
This answer worked for me after upgrading ember-data to version 1.0.0-beta2. At some stage in following the guide I ended up with an older release and there have been breaking changes since then.
Upvotes: 3
Reputation: 8594
Are you trying to run your Ember app from your local filesystem? file:///... To get remote AJAX calls to work you need to be accessing your app via http (or https) using a local server of some sort.
Upvotes: 1
Reputation: 677
I think that you have to set some data model and then connect adapter for this model.
App.BarAdapter = DS.RESTAdapter.extend({
host:'http://myserver.com',
});
App.Bar = DS.Model.extend({
author: DS.attr('string'),
title: DS.attr('string'),
});
Upvotes: 0