Skip to content

Instantly share code, notes, and snippets.

@Blackmist
Created May 13, 2013 15:48
Show Gist options
  • Save Blackmist/5569314 to your computer and use it in GitHub Desktop.
Save Blackmist/5569314 to your computer and use it in GitHub Desktop.
// 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();
}
})
<h2>{{title}}</h2>
<h4>by {{author}}, <small>{{posted}}</small></h4>
{{body}}
<div class="well well-small">
<h4>Tags: <small>{{topics}}</small></h4>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<ul class="nav nav-tabs nav-stacked">
{{#each model}}
<li>
{{#linkTo 'post' this}}{{title}}{{/linkTo}}
</li>
{{/each}}
</ul>
</div>
<div class="span7">
{{outlet}}
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment