I'm trying to use ember together with Rails, but getting an strange error.
It's a very simple nested route test.
I have a rails resource named "Post", just like the video on ember docs:
https://github.com/tildeio/bloggr-client and I've got almost everything working.
http://domain.com/admin#/posts/ works fine
clicking on a post, shows me the details, change the url.
but when I try to load it directly:
http://domain.com/admin#/posts/1
The error happens.
This is my console output:
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>
The strange thing is the url that ember is generating, http://domain.com/post)s/1
Where is this ) comming from?
This is my 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 .
Edit.:
This is the Json that my app is consuming:
{"posts":[{"id":7,"title":"teste","description":"su o autor"}]}
My views:
<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>