0

メッセージに connect-flash ミドルウェアを使用しようとしていますが、機能していないようです。次のエラーが表示されます: ReferenceError: /Users/zc/Documents/tutorials/node-auth/views/addstudent.ejs:14 12|

新しい生徒を追加

13| >>14|

ようこそ: <%= user.local.name %>

15| 16| 17| user は、returnedFn (/Users/zc /Documents/tutorials/node-auth/node_modules/ejs/lib/ejs.js:493:17) View.exports.renderFile [エンジンとして] (/Users/zc/Documents/tutorials/node-auth/node_modules/ejs) /lib/ejs.js:350:31) で View.render (/Users/zc/Documents/tutorials/node-auth/node_modules/express/lib/view.js:76:8) で Function.app.render ( /Users/zc/Documents/tutorials/node-auth/node_modules/express/lib/application.js:502:10) ServerResponse.res.render (/Users/zc/Documents/tutorials/node-auth/node_modules/express) /lib/response.js:777:7) で ServerResponse.res.render (/Users/zc/Documents/tutorials/node-auth/node_modules/express-flash/lib/express-flash.js:29:16) でクエリ。(/Users/zc/Documents/tutorials/node-auth/app/routes.js:78:

これが私のルートです:

  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
  }); 
  });

});

テンプレートにはejsを使用しています。学生ビューをレンダリングするときにオブジェクトとして渡した後でも、ユーザーが定義されていない理由がわかりません。

4

1 に答える 1