将书中app.js的dynamicHelpers代码部分改为:
app.use(function(req, res, next){
var error = req.flash('error');
var success = req.flash('success');
res.locals.user = req.session.user;
res.locals.error = error.length ? error : null;
res.locals.success = success ? success : null;
next();
});
并把此代码放在 app.use(app.router); 之前。
模板文件中改为下面类似结构:
<% if (!locals.user) { %>
<% if ( locals.error ) { %>
<% if ( locals.success ) { %>