0

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>
2
  • This is strange, your code is simple, but gives this error. Can you show your templates? Commented Aug 26, 2013 at 20:18
  • The error is coming from ember data's json serializer, it is trying to determine name of your model by calling toString() but getting (subclass of App.Post) instead of the expected "App.Post". That's also why the url looks crazy. Curious what your API response looks like. Commented Aug 27, 2013 at 1:33

1 Answer 1

2

Updated to lastest versions and everything worked.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.