V
V
Vlad Timofeev2015-01-09 20:34:11
MongoDB
Vlad Timofeev, 2015-01-09 20:34:11

Why is the paginate object not visible?

I followed the example on github: https://github.com/expressjs/express-paginate
1. There is a router.js file in which:

var User       		= require('../app/models/user');
var paginate = require('express-paginate');
....
app.get('/users', function (req, res) {
    User.paginate({}, req.query.page, req.query.limit, function(err, pageCount, users, itemCount) {

    if (err) return next(err);

    res.format({
      html: function() {
        res.render('userss', {
        	page: 'users',
        	users: users,
        	pageCount: pageCount,
        	itemCount: itemCount
        });
      },
      json: function() {
        // inspired by Stripe's API response for list objects
        res.json({
          object: 'list',
          has_more: paginate.hasNextPages(req)(pageCount),
          data: users
        });
      }
    });

  });
});
...

2. user.js file
// app/models/user.js
// load the things we need
var mongoose = require('mongoose');
var bcrypt   = require('bcrypt-nodejs');

// define the schema for our user model
var userSchema = mongoose.Schema({
    facebook         : {
        id           : String,
        token        : String,
        name         : String,
    }, 
     ....
    photoMax: String,
    imgurl: String,
    name: String,
    score: Number,
    about: String,
    contacts: String,
});

userSchema.plugin(require('mongoose-paginate'));
.....
// create the model for users and expose it to our app
module.exports = mongoose.model('User', userSchema);

3. users.jade and _paginate.jade are the same as in the example.
It seems everything should work, but we don’t give paginate to res.render, and therefore here it is:
a8f211189aa94480a8a51485bbbe38ac.png
Help me fix it, please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2015-01-09
@PyTiMa

Perhaps it

// keep this before all routes that will use pagination
app.use(paginate.middleware(10, 50));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question