我正在尝试让我的ember模型使用远程rails api。我试过扩展DS.RESTAdapter,但我不知道如何告诉模型使用这些设置。我的模型永远不会到达localhost:3000。
//app.js
import Ember from 'ember';
import Resolver from 'ember/resolver';
import loadInitializers from 'ember/load-initializers';
Ember.MODEL_FACTORY_INJECTIONS = true;
var App = Ember.Application.extend({
modulePrefix: 'friend-ember-app', // TODO: loaded via config
Resolver: Resolver
});
App.ApplicationAdapter = DS.RESTAdapter.extend({
host: 'localhost:3000',
namespace: 'api/v1'
});
loadInitializers(App, 'friend-ember-app');
export default App;
//
//models/event.js
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string'),
description: DS.attr('string')
});
//
// controllers/index.js
import Ember from 'ember';
export default Ember.Controller.extend({
columns: function(){
//Attempting to see request to remote api
var events = this.store.all('event');
debugger;
return [1,2,3,4];
}.property()
});
答案 0 :(得分:21)
需要在适配器文件夹
中的单独文件中定义和导出适配器在adapters / application.js
中import DS from "ember-data";
var ApplicationAdapter = DS.RESTAdapter.extend({
host: 'localhost:3000',
namespace: 'api/v1'
});
export default ApplicationAdapter;