1
votes

I'm trying to take the simple TodoMVC demo application from the emberjs.com website (http://emberjs.com/guides/getting-started/) and add some functionality to it, in order to learn more about how Ember works. I've run into a variety of "gotchas" so far that I've managed to get past, but now I'm completely stuck.

The primary feature I'm trying to add to the application now is having multiple lists, each with their own set of items. The request is being handled by the correct Controller and action, but a new List record won't get created. The specific error I am getting is "TypeError: type._create is not a function".

Can anyone tell me what that error means, and/or what I'm doing wrong here?

Here's the code that I'm working with at the moment:

Ember      : 1.4.0
Handlebars : 1.3.0
jQuery     : 1.11.0

Todos.ListsController = Ember.ArrayController.extend({
  actions: {
    createList: function() {
      var title = this.get('newList');
      if(!title.trim()) { return; }
      var list = this.store.createRecord('list', { title: title });
      this.set('newList', '');
      list.save();
    }
  }
});

Todos.List = DS.Model.extend({
  title: DS.attr('string')
});

<header class="header">
  <h1>Lists</h1>
  {{input type="text" id="new-list" placeholder="Add a List" value=newList action="createList"}}
</header>

<section class="main">
  <ul id="todo-lists">
    {{#each list in controller}}
      <li>
        <label>{{list.title}}</label>
        <button class="destroy"></button>
      </li>
    {{/each}}
  </ul>
</section>
1
at which line is the error occurring? - bejonbee
In ember-data.js, line 1581 - CallMeEsmale

1 Answers

0
votes

I ran into a similar issue trying to follow the guide on emberjs.com. I was building the ember app on top of a rails 4 app using the ember-rails gem. It was eventually resolved when I updated to the latest beta version of ember-data.

You didn't list your ember-data version number but that may be the culprit for your errors as the syntax of createRecord that you used looks correct.

When trying to troubleshoot my problem I came across this issue posted in the github repository In the issue it outlines a different problem that I also experienced when trying to follow the guide, at the bottom of the comments it is mentioned that the "latest (v1.0.0-beta.4 at the moment)" version of ember-data should be used. I inspected the ember-data.js file in my browser inspector and at the top I noticed

// Version: v0.14
// Last commit: d9cd270 (2013-08-31 17:12:14 -0700)

Since I am rails and using the rails-ember gem, I was able to update it through:

$ rails generate ember:install --channel=beta

After running that command I restarted the webserver and inspected the ember-data.js file again and saw

/*!
 * @overview  Ember Data
 * @copyright Copyright 2011-2014 Tilde Inc. and contributors.
 *            Portions Copyright 2011 LivingSocial Inc.
 * @license   Licensed under MIT license (see license.js)
 * @version   1.0.0-beta.7.f87cba88
 */

The issues I was experiencing literally disappeared without any alteration to the code.

That error you are experiencing comes from ember-data as that is the part of the library that handles the store functions. That part of ember.js is under heavy development at the moment so I would suggest making sure you are using the latest beta version. if you are not using rails for a backend, you can download the .js file from emberjs.com.

I hope this helps, I've been experiencing a lot of frustrating errors trying to get ember to work on rails over the past week, and I think this issue was the cause of most of my problems.