Ember不会调用rails后端

时间:2016-05-04 18:45:42

标签: ruby-on-rails-3 ember.js ember-data

我正在开发一个前端为ember,后端为rails的项目。 Rails服务器在3000端口上运行,并在4200端口上运行。我有一个ember模型错误,在我的routes / index.js代码中,

this.store.findAll('bug')

我收到以下错误

GET http://localhost:4200/bugs 404 (Not Found)

以下是我的适配器

# app/adapters/application.js

import ActiveModelAdapter from 'active-model-adapter';
import ENV from '../config/environment';

export default ActiveModelAdapter.extend({
  namespace: 'api/v1',
  host: ENV['serverURL']     // ENV['serverURL'] is http://localhost:3000
});

我没有看到任何请求进入后端服务器。如果您需要任何进一步的信息,请与我们联系。

1 个答案:

答案 0 :(得分:2)

好吧,它向http://localhost:4200/bugs提出请求,因此ENV['serverURL'] 不是 http://localhost:3000!你用调试器检查过这个吗?

但是你使用的是什么样的ember版本?据我所知,DS.ActiveModelAdapter不是ember-data 2.5.2的一部分,而是额外的addon

您是否也为CORS配置了rails后端?我建议您使用--proxy= http://localhost:3000进行开发,然后使用rails在生产中提供已编译的ember应用程序。