1
votes

i face this error when saving data to api

Uncaught Error: Assertion Failed: Cannot delegate set('firstName', a) to the 'content' property of object proxy <>: its 'content' is undefined

below is my code

import Ember from 'ember';


export default Ember.ObjectController.extend({
    isValid: Ember.computed(
        'email',
        'firstName',
        'lastName',
        'twitter',
        function() {
            return !Ember.isEmpty(this.get('email')) &&
            !Ember.isEmpty(this.get('firstName')) &&
            !Ember.isEmpty(this.get('lastName')) &&
            !Ember.isEmpty(this.get('twitter'));
        }
        ),
    actions:{
        save: function() {
            if (this.get('isValid')) {
                var _this = this;
                this.get('model').save().then(function(friend) {
                    _this.transitionToRoute('friends.show', friend);
                });
            } else {
                this.set('errorMessage', 'You have to fill all the fields');
            }
        },
        cancel: function() {
            this.transitionToRoute('friends');
        }

    }

});
2
Ember is telling you that the content property of the controller is not set, did you set the model in the route model hook? please add the code for your route. - MartinElvar
I got this error. Turned out I had duplicate controller. - Stoutie

2 Answers

3
votes

Don't use ObjectController. Use simply Ember.Controller.extend.

0
votes

I see this on the ember-cli-101 book. I encountered the same issue myself. It's likely that you are not properly setting the model attribute in your route. Based on the book, the error either occurs in the edit or new route.

if your router.js looks like this:

...
Router.map(function() {
  this.resource('friends', function() {
    this.route('new');
    this.route('show', { path: ':friend_id' });
    this.route('edit', { path: ':friend_id/edit' });
  });
});
...

the friends/index route needs to set the model attribute:

import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    return this.store.find('friend');
  },
});

and the friends/new route needs to set the model in a different way: import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    return this.store.createRecord('friend');
  },
});

For anyone not familiar with the book (mentioned above) the question is from code that is in the book, which is why I referenced it. In most cases, if you get this issue it is likely because you forgot to or did not set up the model attribute correctly in the appropriate route.