我正在尝试将ember与Rails一起使用,但遇到了一个奇怪的错误。
这是一个非常简单的嵌套路由测试。
我有一个名为“Post”的rails资源,就像ember docs上的视频一样:
https://github.com/tildeio/bloggr-client我几乎一切都在运作。
http://domain.com/admin#/posts/ works fine
点击帖子,向我显示详细信息,更改网址。
但是当我尝试直接加载它时:
http://domain.com/admin#/posts/1
发生错误。
这是我的控制台输出:
DEBUG: ------------------------------- ember.js?body=1:382
DEBUG: Ember.VERSION : 1.0.0-rc.7 ember.js?body=1:382
DEBUG: Handlebars.VERSION : 1.0.0 ember.js?body=1:382
DEBUG: jQuery.VERSION : 1.10.2 ember.js?body=1:382
DEBUG: ------------------------------- ember.js?body=1:382
Assertion failed: Your model must not be anonymous. It was (subclass of App.Post) ember.js?body=1:382
GET http://localhost:3000/post)s/1 404 (Not Found) jquery.js?body=1:8707
Error while loading route:
Class {id: "1", store: Class, _reference: Object, currentState: Object, _changesToSync: Object…}
ember.js?body=1:382
Uncaught <(subclass of App.Post):ember269:1>
奇怪的是ember正在生成的网址http://domain.com/post)s/1
这是从哪里来的?
这是我的js:
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap_bootstrap
//= require chosen-jquery
//= require bootstrap-wysihtml5
//= require bootstrap-wysihtml5/locales/pt-BR
//= require handlebars
//= require ember
//= require ember-data
//= require_self
// for more details see: http://emberjs.com/guides/application/
App = Ember.Application.create({
rootElement: '#ember_root'
});
App.Store = DS.Store.extend({
revision: 12,
adapter: DS.RESTAdapter
});
App.Router.map(function() {
this.resource('posts', function() {
this.resource('post', { path: ':post_id' });
});
});
App.PostsRoute = Ember.Route.extend({
model: function() {
return App.Post.find();
}
});
var attr = DS.attr;
App.Post = DS.Model.extend({
title: attr('string'),
description: attr('string')
});
//= require_tree .
编辑:
这是我的应用正在消耗的Json:
{"posts":[{"id":7,"title":"teste","description":"su o autor"}]}
我的观点:
<script type="text/x-handlebars">
<div class="row">
<div class="span9">
{{outlet}}
</div>
<div class="span3">
<div class="well sidebar-nav">
<h3>Ember Sidebar</h3>
<ul class="nav nav-list">
<li class="nav-header">Sidebar</li>
<li>{{#linkTo 'posts'}}Posts{{/linkTo}}</li>
</ul>
</div>
</div>
</div>
</script>
<script type="text/x-handlebars" id="posts">
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<table class='table'>
<thead>
<tr><th>Recent Posts</th></tr>
</thead>
{{#each model}}
<tr><td>
{{#linkTo 'post' this}}{{title}}{{/linkTo}}
</td></tr>
{{/each}}
</table>
</div>
<div class="span9">
{{outlet}}
</div>
</div>
</div>
</script>
<script type="text/x-handlebars" id="posts/index">
<p class="text-warning">Please select a post</p>
</script>
<script type="text/x-handlebars" id="post">
<h1>{{title}}</h1>
<h2>{{{description}}}</h2>
<hr>
</script>
答案 0 :(得分:2)
更新到最新版本,一切正常。