Created
June 30, 2015 17:41
-
-
Save kayue/8e046c2c26552e8f5c1a 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
// Create view | |
Posts.views.add("latest", function (terms) { | |
return { | |
options: {sort: {lastCommentedAt: -1}} | |
}; | |
}); | |
// Route controller | |
Posts.controllers.latest = Posts.controllers.list.extend({ | |
view: "latest" | |
}); | |
// Create route | |
Router.route('/latest', { | |
name: 'posts_latest', | |
controller: Posts.controllers.latest | |
}); | |
// Override default "/" route | |
Router.onBeforeAction(function () { | |
if (Router.current().route.getName()==="posts_default") { | |
this.render("posts_list_controller", { | |
data: { | |
terms: { | |
view: 'latest', // ideally this should reuse Posts.controllers.latest's data | |
limit: 10 | |
} | |
} | |
}); | |
} else { | |
this.next(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment