In Ember.js, controllers allow you to decorate your models with display logic; models have properties that are sent to the server and controllers have properties that do not need to be sent to the server.
The generator will create a controller that will control the edit view; let's add some logic that will handle saving and destroying a model.
Open the app/scripts/controllers/post_edit_controller.coffee
file and add the following content:
LearningYeomanCh5.PostEditController = Ember.ObjectController.extend( needs: 'post' actions: save: -> @get('model').save() @transitionToRoute 'post', @get('model') destroy: -> @get('model').deleteRecord() @transitionToRoute 'posts' )
The preceding code does the following:
The
PostEditController
class is defined extending theEmber.ObjectController
classThe
needs
property specifies that this controller depends on thepost
controllerThe
actions
object declares asave
action and adestroy...