1

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
  • 1
    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. Commented Sep 21, 2014 at 6:12
  • I got this error. Turned out I had duplicate controller. Commented Feb 13, 2015 at 20:43

2 Answers 2

3

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

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

2 Comments

I don't think there is anything particularly wrong with using Ember.ObjectController; at least in the current version 1.8.0. However, moving towards Ember 2.0 Controllers will be deprecated, essentially replaced by components (I believe)
Well, for smooth transition to Ember 2.0 It would be wise to switch to Ember.Controller, and create the model attribute in a component. But for the current versions Ember.ObjectController should be fine
0

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.

3 Comments

I'm getting this error on the edit route. I've defined the model in routes/friends/edit as such model: function(params) { return this.store.find('friend', params.friend_id); } but I'm still getting an error when I hit the cancel button from the edit page. Any pointers?
@DavidBecerra the edit route doesn't actually need this model hook. routes/friends/edit.js should just have the export default Ember.Route.extend({}); the model hook you showed above should be in the routes/folders/index.js. If this doesn't solve the issue, do you have the code repo hosted on github?
About a second after I posted I realized my mistake. In the controller I was using this instead of this.get('model'). So I had this.transitionToRoute('friends.show', this) vs. this.transitionToRoute('friends.show', this.get('model')).

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.