Skip to content

Instantly share code, notes, and snippets.

Created November 30, 2014 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/b57fb71432c362833d18 to your computer and use it in GitHub Desktop.
Save anonymous/b57fb71432c362833d18 to your computer and use it in GitHub Desktop.
/**
* CityController
*
* @description :: Server-side logic for managing cities
* @help :: See http://links.sailsjs.org/docs/controllers
*/
module.exports = {
/*
*
*/
index: function (req, res, next) {
var currentPage = 1;
var pageLimit = 15;
if (req.query.page != 'undefined')
currentPage = req.query.page;
var totalCities = 0;
City.count(function (err, totalCities) {
if (err) return console.log(err);
City.find().populate('countryId').paginate({ page: currentPage, limit: pageLimit }).exec(function (err, cities) {
if (err) return next(err);
res.view({
cities: cities,
currentPage: currentPage,
pageCount: Math.ceil(totalCities/pageLimit)
});
});
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment