I have been trying to use the connect-flash middleware for messages but it doesnt seem to be working. I get the following error: ReferenceError: /Users/zc/Documents/tutorials/node-auth/views/addstudent.ejs:14 12|
Add a new Student
13| >> 14|Welcome: <%= user.local.name %>
15| 16| 17| user is not defined at eval (eval at (/Users/zc/Documents/tutorials/node-auth/node_modules/ejs/lib/ejs.js:464:12), :11:23) at returnedFn (/Users/zc/Documents/tutorials/node-auth/node_modules/ejs/lib/ejs.js:493:17) at View.exports.renderFile [as engine] (/Users/zc/Documents/tutorials/node-auth/node_modules/ejs/lib/ejs.js:350:31) at View.render (/Users/zc/Documents/tutorials/node-auth/node_modules/express/lib/view.js:76:8) at Function.app.render (/Users/zc/Documents/tutorials/node-auth/node_modules/express/lib/application.js:502:10) at ServerResponse.res.render (/Users/zc/Documents/tutorials/node-auth/node_modules/express/lib/response.js:777:7) at ServerResponse.res.render (/Users/zc/Documents/tutorials/node-auth/node_modules/express-flash/lib/express-flash.js:29:16) at Query. (/Users/zc/Documents/tutorials/node-auth/app/routes.js:78:15) at /Users/zc/Documents/tutorials/node-auth/node_modules/mongoose/node_modules/kareem/index.js:177:19 at /Users/zc/Documents/tutorials/node-auth/node_modules/mongoose/node_modules/kareem/index.js:109:16 at doNTCallback0 (node.js:407:9) at process._tickCallback (node.js:336:13)Here is my route:
app.post('/addstudent', isLoggedIn, function(req, res){
console.log(req.body.selectoptions);
var studentDetails = {};
var newStudent = new Student(studentDetails);
newStudent.save(function(err, student){
if (err) throw err;
console.log(student);
res.render('student', {
user: req.user
});
});
});
I am using ejs for the templating. I'm not sure why I'm getting user not defined, even after passing it along as an object when rendering student view.