index.js
This file
Path
examples/mvc/controllers/user/index.js
41 lines · 873 bytes · JavaScript
Last changed by
docs: add missing apostrophe in example (#7483)Chris Zbefore adoption9169cbe
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142'use strict'
/** * Module dependencies. */
var db = require('../../db');
exports.engine = 'hbs';
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]; // can't 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);};