jeudi 8 janvier 2015

ember - putting save action in route but then how to set model

i have a projects resource with nested tasks. i am attempting to save a task.


i originally had the save action in my controller and worked, but i moved it to my routes/tasks/new.js


now i cannot seem to set the model properly.


this is what i have so far:



import Ember from 'ember';

export default Ember.Route.extend({
model: function() {
return this.modelFor('task');
},

actions: {
save: function() {
var _this = this;
this.get('task').save().then(function() {
_this.set('task', _this.store.createRecord('task'));
_this.transitionToRoute('tasks');
}, function(){
alert("That failed!");
});
},

cancel: function() {
this.transitionToRoute('tasks');
}
}
});


i have also tried using return this.store.createRecord('task') as my model. and replacing task with currentModel when i do that.


this is my Router:



Router.map(function() {
this.resource('projects', function() {
this.route('show', { path: ':project_id'}, function() {
this.resource('tasks', function() {
this.route('show', { path: ':id'});
this.route('new');
this.route('edit');
});
});
this.route('edit', { path: ':project_id/edit'});
this.route('new');
});
});

Aucun commentaire:

Enregistrer un commentaire