index.js
This file
Path
examples/mvc/controllers/user/index.js
37 lines · 833 bytes · JavaScript
Last changed by
Not known.
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738/** * Module dependencies. */
var db = require('../../db');
exports.before = function(req, res, next){ var id = req.params.user_id; if (!id) return next(); // pretend to query a database... process.nextTick(function(){ req.user = db.users[id]; // cant find that user if (!req.user) return next('route'); // found it, move on to the routes next(); });};
exports.list = function(req, res, next){ res.render('list', { users: db.users });};
exports.edit = function(req, res, next){ res.render('edit', { user: req.user });};
exports.show = function(req, res, next){ res.render('show', { user: req.user });};
exports.update = function(req, res, next){ var body = req.body; req.user.name = body.user.name; res.message('Information updated!'); res.redirect('/user/' + req.user.id);};