Search code examples
ember.jscontrollerassertions

Emberjs TODO-list. cannot create new 'todo'


I am trying make a remake of the todo list with a different name called 'newpermitcategory'. My code seems to match the examples on the emberjs website but i am still receiving this error when I try to make a new permittype (todo).

Uncaught TypeError: Cannot call method 'trim' of undefined 

**I spelled the plural of newpermitcategory as newpermitcategorys on purpose.

This is the code

<h2>New Permit Category</h2> 
  {{input type="text" id="newpermitcategory" placeholder="Create a category and press enter" value=newPermittype action="createPermitcategory"}}
<tr id="newpermitcategory">
{{#each}}
  <td>
    <input type="checkbox" class="toggle">
    <label>{{permittype}}</label> lol
  </td>
{{/each}}
</tr>

VpcYeoman.NewpermitcategorysController = Ember.ArrayController.extend({
  actions: {
    createPermitcategory: function () {
      var permittype = this.get('newPermittype');
      if (!permittype.trim()) {return;}

      var newpermitcategory = this.store.createRecord('newpermitcategory', {
        permittype: permittype
      });

      this.set('newPermittype', '');

      newpermitcategory.save();
    }
  }
});

VpcYeoman.Newpermitcategory = DS.Model.extend({
    permittype: DS.attr('string'),
    isCompleted: DS.attr('boolean')
});

VpcYeoman.Newpermitcategory.FIXTURES = [
  {
    id: 1,
    permittype:'Building'
  },
  {
    id: 2,
    permitType:'Electrical'
  },
  {
    id: 3,
    permittype:'Zoning'
  },
  {
    id: 4,
    permittype:'Fire'
  }
];


VpcYeoman.Router.map(function () {
  this.resource('newpermitcategorys', { path: '/newpermitcategorys' });
  this.resource('newpermitcategory', { path: '/newpermitcategory/:newpermitcategory_id' });
});

VpcYeoman.NewpermitcategoryView = Ember.View.extend({
    templateName: 'newpermitcategory'
});

VpcYeoman.NewpermitcategorysView = Ember.View.extend({
    templateName: 'newpermitcategorys'
});


VpcYeoman.NewpermitcategorysRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('newpermitcategory');
  }
});

VpcYeoman.Newpermitcategoryroute = Ember.Route.extend({

});

EDIT: I had originally made a lot of capitalization mistakes. Naming conventions are so important in Emberjs


Solution

  • your route and controller names are incorrect

    NewpermitcategorysController

    NewpermitcategorysRoute

    NewpermitcategoryView

    and your action name doesn't match

    createPermitcategory and createPermitCategory

    and the field newPermittype doesn't exist, you are setting the input value to a constant "newPermittype" not the field newPermittype

    http://emberjs.jsbin.com/OxIDiVU/15/edit