【发布时间】:2015-12-23 03:37:37
【问题描述】:
作为 Ember.js 的初学者,我尝试从我的 Rails Api 服务器获取一些数据到 Ember 应用程序。我的 Ember 应用程序正在尝试获取并显示从 rails api 提供的类别名称。 我正在使用
- Ember 版本:1.13.8
- 节点:0.12.7
- npm: 2.13.4
app/router.js
Router.map(function() {
this.resource('categories',function(){
this.resource('category',{path: '/:category_id'});
});
});
路由/类别/index.js
export default Ember.Route.extend({
model() {
return this.store.findAll('category')
}
});
app/models/category.js
export default DS.Model.extend({
name: DS.attr('string')
});
app/adapters/application.js
export default DS.JSONAPIAdapter.extend({
shouldReloadAll: function() { return true; },
namespace: 'v1',
host: 'http://ip.address-to_rails_api'
});
app/templates/categories/index.hbs
<ul>
{{#each model as |category|}}
<li>{{category.name}}</li>
{{/each}}
</ul>
现在,当我在浏览器中访问 http://ip.address-to_rails_api 时,我会收到响应
{"categories":[{"id":1,"name":"Entertainment"}, {"id":2,"name":"Education"}]}
但是当我在我的 ember 应用程序中访问 /categories 时,即http://localhost:4200/categories 注意显示在浏览器中,我在 ember 检查器中收到错误
routeName: "categories.index_error"
context: Error: Adapter operation failed
currentModel: Error: Adapter operation failed
ember 服务器控制台也反映错误
Content Security Policy violation: {}
我也尝试将 JSONAPIAdapter 更改为 RESTAdapter,但它给出了弃用错误。请帮我理解问题。
【问题讨论】:
-
我在这里遇到了同样的问题stackoverflow.com/questions/32670533/…。不幸的是,我现在没有解决方案
-
需要注意的一点是,我认为“资源”在 1.13.8 之前已被弃用。
-
是的,我将资源更改为路由,但问题出在其他问题上。 ember 引起的主要问题是由于代码的指数变化。他们正在以非常快的速度对其进行更改,因此每个东西都会在一个月后被弃用。
标签: javascript ruby-on-rails ember.js ember-data ember-cli