Permalink
Browse files

Augmented the postsList route to take a limit

chapter12-2
  • Loading branch information...
tmeasday committed Apr 8, 2013
1 parent fa34863 commit c29806037c82830e558ec271c821d7feccbbf57e
Showing with 21 additions and 10 deletions.
  1. +0 −5 client/templates/posts/posts_list.js
  2. +15 −3 lib/router.js
  3. +6 −2 server/publications.js
@@ -1,5 +0,0 @@
Template.postsList.helpers({
posts: function() {
return Posts.find({}, {sort: {submitted: -1}});
}
});
View
@@ -3,12 +3,10 @@ Router.configure({
loadingTemplate: 'loading',
notFoundTemplate: 'notFound',
waitOn: function() {
return [Meteor.subscribe('posts'), Meteor.subscribe('notifications')]
return [Meteor.subscribe('notifications')]
}
});
Router.route('/', {name: 'postsList'});
Router.route('/posts/:_id', {
name: 'postPage',
waitOn: function() {
@@ -24,6 +22,20 @@ Router.route('/posts/:_id/edit', {
Router.route('/submit', {name: 'postSubmit'});
Router.route('/:postsLimit?', {
name: 'postsList',
waitOn: function() {
var limit = parseInt(this.params.postsLimit) || 5;
return Meteor.subscribe('posts', {sort: {submitted: -1}, limit: limit});
},
data: function() {
var limit = parseInt(this.params.postsLimit) || 5;
return {
posts: Posts.find({}, {sort: {submitted: -1}, limit: limit})

This comment has been minimized.

Show comment
Hide comment
@franmartin91

franmartin91 Jul 23, 2017

"return posts" not is correct. The correct name is "post".

Regards.

@franmartin91

franmartin91 Jul 23, 2017

"return posts" not is correct. The correct name is "post".

Regards.

};
}
});
var requireLogin = function() {
if (! Meteor.user()) {
if (Meteor.loggingIn()) {
View
@@ -1,5 +1,9 @@
Meteor.publish('posts', function() {
return Posts.find();
Meteor.publish('posts', function(options) {
check(options, {
sort: Object,
limit: Number
});
return Posts.find({}, options);
});
Meteor.publish('comments', function(postId) {

3 comments on commit c298060

@zhenhappy

This comment has been minimized.

Show comment
Hide comment
@zhenhappy

zhenhappy Oct 27, 2015

学到这个为 postsList 路径添加限制的时候后台会有报错,不知是何原因

I20151027-08:21:07.096(8)? Exception from sub posts id XHMB3sqibSaEmtWnk Error: Match error: Expected object, got undefined
I20151027-08:21:07.097(8)? at checkSubtree (packages/check/match.js:275:1)
I20151027-08:21:07.097(8)? at check (packages/check/match.js:32:1)
I20151027-08:21:07.097(8)? at [object Object].Meteor.publish.Comments.find.postId as _handler
I20151027-08:21:07.097(8)? at packages/check/match.js:109:1
I20151027-08:21:07.097(8)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151027-08:21:07.097(8)? at Object.Match.failIfArgumentsAreNotAllChecked (packages/check/match.js:108:1)
I20151027-08:21:07.097(8)? at maybeAuditArgumentChecks (livedata_server.js:1689:18)
I20151027-08:21:07.097(8)? at [object Object].
.extend.runHandler (livedata_server.js:1023:17)
I20151027-08:21:07.097(8)? at [object Object].
.extend.startSubscription (livedata_server.js:842:9)
I20151027-08:21:07.097(8)? at [object Object].
.extend.protocol_handlers.sub (livedata_server.js:614:12)
I20151027-08:21:07.098(8)? Sanitized and reported to the client as: Match failed [400]

学到这个为 postsList 路径添加限制的时候后台会有报错,不知是何原因

I20151027-08:21:07.096(8)? Exception from sub posts id XHMB3sqibSaEmtWnk Error: Match error: Expected object, got undefined
I20151027-08:21:07.097(8)? at checkSubtree (packages/check/match.js:275:1)
I20151027-08:21:07.097(8)? at check (packages/check/match.js:32:1)
I20151027-08:21:07.097(8)? at [object Object].Meteor.publish.Comments.find.postId as _handler
I20151027-08:21:07.097(8)? at packages/check/match.js:109:1
I20151027-08:21:07.097(8)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151027-08:21:07.097(8)? at Object.Match.failIfArgumentsAreNotAllChecked (packages/check/match.js:108:1)
I20151027-08:21:07.097(8)? at maybeAuditArgumentChecks (livedata_server.js:1689:18)
I20151027-08:21:07.097(8)? at [object Object].
.extend.runHandler (livedata_server.js:1023:17)
I20151027-08:21:07.097(8)? at [object Object].
.extend.startSubscription (livedata_server.js:842:9)
I20151027-08:21:07.097(8)? at [object Object].
.extend.protocol_handlers.sub (livedata_server.js:614:12)
I20151027-08:21:07.098(8)? Sanitized and reported to the client as: Match failed [400]

@danielbh

This comment has been minimized.

Show comment
Hide comment
@danielbh

danielbh Feb 6, 2016

I also got the above error message on my system @zhenhappy

I also got the above error message on my system @zhenhappy

@tonykean888

This comment has been minimized.

Show comment
Hide comment
@tonykean888

tonykean888 Mar 13, 2016

@zhenhappy,@danielbh
change Post => Posts at data:function of Router.route('/:postsLimit?' ... "

@zhenhappy,@danielbh
change Post => Posts at data:function of Router.route('/:postsLimit?' ... "

Please sign in to comment.