Handling form submission, params, access to model


#1

(Warning: newbie) Going around the block on this one, as each example I see does it differently (and none work for me)

var InitiativesNewRoute = Ember.Route.extend({
  model: function(params) {
    return this.store.createRecord('initiative', params);
  },

  actions: {
    submit: function() {
      var initiative = this.get('model');
      initiative.save().then(function(model) {
        this.transitionTo('initiatives.show', initiative);
      });
    }
  }
});

Saving barfs as initiative is undefined, but I see a record created in the ember chrome plugin. So it looks like creating the record in model works, but fetching it in the action doesn’t.

Also tried this example:

submit: function(initiative) {
  initiative.save().then(function(model) {
    this.transitionTo('initiatives.show', initiative);
  });
}

Without passing passing params to createRecord above, and I get the same error. How do I do this?

Using ember-cli 0.0.39 and easy-form, with the fixture adapter.


#2

Got some help on #emberjs and managed to get it working like this:

var InitiativesNewRoute = Ember.Route.extend({
  model: function(params) {
    return this.store.createRecord('initiative', params);
  },

  actions: {
    submit: function() {
      var _this = this;
      var initiative = this.get('controller.model');
      initiative.save().then(function(model) {
        _this.transitionTo('initiatives.show', model.get('id'));
      });
    }
  }
});