Created
May 13, 2013 15:48
-
-
Save Blackmist/5569314 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Newpost controller | |
App.NewpostController = Ember.ObjectController.extend({ | |
title: '', | |
author: '', | |
body: '', | |
save: function() { | |
//create the post | |
var now = new Date(); | |
var post=App.Post.create({ | |
title: this.get('title'), | |
author: this.get('author'), | |
body: this.get('body'), | |
posted: now.toString('dddd, MMMM, yyyy'), | |
}); | |
post.save(); | |
// set these back to '' so the form is pretty | |
this.set('title',''); | |
this.set('author',''); | |
this.set('body',''); | |
//transition back to posts | |
this.transitionToRoute('posts'); | |
} | |
}); | |
App.Router.map(function () { | |
// put your routes here | |
this.resource('posts', function() { | |
this.resource('post', { path: ':post_id' }); | |
}); | |
this.resource('newpost'); | |
}); | |
//redirect to posts | |
App.IndexRoute = Ember.Route.extend({ | |
redirect: function() { | |
this.transitionTo('posts'); | |
} | |
}); | |
App.PostsRoute = Ember.Route.extend({ | |
model: function () { | |
return App.Post.findAll(); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment