Skip to content

Instantly share code, notes, and snippets.

@walter
Created February 7, 2013 03:29
Show Gist options
  • Select an option

  • Save walter/4728166 to your computer and use it in GitHub Desktop.

Select an option

Save walter/4728166 to your computer and use it in GitHub Desktop.
Example blog application route handlers and the mixin they use
# see mixins/posts_formable below
App.PostsNewRoute = Ember.Route.extend App.PostsFormable,
# set up a new blank instance of Post for the form's content
model: ->
App.Post.createRecord()
# perhaps alternatively, this could use 'needs post' in controller
# for setting the model instance
App.PostEditRoute = Ember.Route.extend App.PostsFormable,
model: ->
@modelFor 'post'
# form mixin used by both new and edit
# mixin, so new and edit can use same template/view
App.PostsFormable = Ember.Mixin.create
renderTemplate: ->
@render 'posts/form', ->
outlet: 'modal'
events:
cancel: (post) ->
post.transaction.rollback()
@transitionTo 'posts'
submit: (post) ->
# TODO: add validation handling
post.get('store').commit()
if post.didCreate
@transitionTo 'posts'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment