Ember.js: model interaction in controller or route? -
is considered ember.js best practice keep model interactions -- creation, -- in route, or controller?
an example: following coffeescript works fine, , works if 'save' logic moved controller. 1 practice preferred on other, , if so, why?
app.usersnewroute = ember.route.extend model: -> app.user.createrecord() setupcontroller: (controller, model) -> controller.set('content', model) events: { save: (user) -> user.on "didcreate", @, () -> @transitionto 'users.show', user @get('store').commit() }
in general, if action affects state in particular controller, or model that controller fronts, should handle in controller. if affects broader application state (i.e. controller), or results in route transition, or should handled different logic based on state of app, should handled in router.
Comments
Post a Comment