Skip to content

Instantly share code, notes, and snippets.

@geekygrappler
Last active August 29, 2015 14:21
Show Gist options
  • Save geekygrappler/1e8743ea5bcd575742fb to your computer and use it in GitHub Desktop.
Save geekygrappler/1e8743ea5bcd575742fb to your computer and use it in GitHub Desktop.
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.find('todo');
},
actions: {
// Additional lines truncated for brevity...
acceptChanges: function(todo) {
if (Ember.isEmpty(todo.get('title'))) {
this.send('deleteTodo', todo);
} else {
todo.save();
}
},
deleteTodo: function(todo) {
todo.deleteRecord();
}
}
});
@virgiliud
Copy link

Would it be better to handle the delete in the todo-item component? For example:

acceptChanges: function(todo) { // todo is todo.title
    this.set('isEditing', false);
    if (todo === "") { 
        this.sendAction('deleteTodo', this.todo);
    }
},

...and remove acceptChanges entirely from the route.

Also it looks like the input helper is saving any changes so todo.save(); might not be required?

@ryrych
Copy link

ryrych commented Jun 29, 2015

Hi, in Edit and Delete Todos section todoRoute is not generated with cli. It is later, in Child Routes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment