在sailjs 500内部服务器错误

我是sailsjs中的新手,并试着按照教程学习,我在插入post的时候出现了500内部错误。

这是我的所有文件:

//DashboardController.js newpost: function(req, res){ var params = req.params.all(); var userId = req.session.user_detail._id; //return false; Post.create({ title: params.heading, description: params.message, posted_by: params.userId }).done(function(error, post_created){ if(err){ }else{ req.session.post_details = post_created; res.redirect('/dashboard'); } }); } 

// Dashboard.js模型

 module.exports = { attributes: { title:{ type:'string', required:true, columnName:'title' }, description: { type:'text', columnName:'description' }, posted_by: { type: 'integer', columnName: 'posted_by' } } }; 

// ejs文件

  <div class="col-sm-7"> <h3>Post Feed Now</h3> <br> <div class="media"> <div class="media-body"> <form method="POST" action="/dashboard/newpost"> <table class="table"> <tr><td>Heading</td><td><input type="text" class="form-control" name="heading"></td></tr> <tr><td>Message</td><td><textarea name="message" class="form-control"></textarea></td></tr> <tr><td colspan="2"><input type="submit" class="btn btn-primary" value="Post Now"/></td></tr> </form> </table> </div> 

 and error in terminal error: Sending 500 ("Server Error") response: ReferenceError: Post is not defined at Object.module.exports.newpost (/var/www/html/sailsTemplate/api/controllers/DashboardController.js:21:3) at bound (/usr/lib/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21) at routeTargetFnWrapper (/usr/lib/node_modules/sails/lib/router/bind.js:179:5) at callbacks (/usr/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37) at param (/usr/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11) at param (/usr/lib/node_modules/sails/node_modules/express/lib/router/index.js:135:11) at pass (/usr/lib/node_modules/sails/node_modules/express/lib/router/index.js:145:5) at nextRoute (/usr/lib/node_modules/sails/node_modules/express/lib/router/index.js:100:7) at callbacks (/usr/lib/node_modules/sails/node_modules/express/lib/router/index.js:167:11) at /usr/lib/node_modules/sails/lib/router/bind.js:187:7 at alwaysAllow (/usr/lib/node_modules/sails/lib/hooks/policies/index.js:207:11) at routeTargetFnWrapper (/usr/lib/node_modules/sails/lib/router/bind.js:179:5) at callbacks (/usr/lib/node_modules/sails/node_modules/express/lib/router/index.js:164:37) at param (/usr/lib/node_modules/sails/node_modules/express/lib/router/index.js:138:11) at param (/usr/lib/node_modules/sails/node_modules/express/lib/router/index.js:135:11) at pass (/usr/lib/node_modules/sails/node_modules/express/lib/router/index.js:145:5) [ReferenceError: Post is not defined] 

我想在mongodb中创build插入post,我们必须创build集合mongo db或代码自动创build集合,同时插入..

我不知道为什么我得到这个问题500内部服务器。

如果有任何要求,请问我

Solutions Collecting From Web of "在sailjs 500内部服务器错误"

如果您的模型文件名是Dashboard.jsDashboard.jsreplacePost.create

 newpost: function(req, res){ var params = req.params.all(); var userId = req.session.user_detail._id; Dashboard.create({ title: params.heading, description: params.message, posted_by: params.userId }).done(function(error, post_created){ if(err){ }else{ req.session.post_details = post_created; res.redirect('/dashboard'); } }); } 

如果您希望Post作为您的模型的名称,则必须将您的模型文件重命名为Post.js