エクスプレスとマングースでnodejsを使ってCRUDを作成しようとしていますが、フォームからコンテンツを更新しようとすると、それはPOSTメソッドで行います。ここに私のコードは付属しています。node.jsにputメソッドを使用して更新情報を表現する方法
ジェイドテンプレート
extends ../includes/layout
block content
div(class="wrap")
include ../includes/header
div(class="column-group vertical-space")
div(class="all-50 push-center")
div(class="all-100")
h1 #{title}
div(class="all-100")
form(role="form" method="post" action="#{project.id}" enctype="multipart/form-data")
div(class="all-50")
h3 Cambiar nombre a #{project.ProjectName}
input(type="text" name="projectName" required)
p Cambiar detalles
textarea(name="details")
p Cambiar precio
input(type="number" name="ammount")
p Cambiar localización
input(type="text" name="localize")
div(class="all-50")
p Cambiar Imágen
input(type="file" name="image" multiple)
//p #{plane}
//input(type="file" name="plane")
div(class="all-100")
button(type="submit") Enviar
div(class="push")
include ../includes/footer
コントローラ
saveEditProject : function (req, res, file){
Project.findById(req.params.id, function(err, project){
if(!project){
res.redirect('/project');
}
project.ProjectName = req.body.projectName;
project.ProjectDetails = req.body.details;
project.ProjectAmount = req.body.ammount;
project.ProjectLocation = req.body.localize;
project.ProjectFileName = req.body.image;
project.save(function (err) {
if (err) {
res.send("not now");
}
res.redirect('/project');
});
});
},
ルート
router.post('/edit/:id', controller.saveEditProject);
[router.put'](http://expressjs.com/en/4x/api.html#router.METHOD) –
をこのように使用すると、http:// localhost:3000/project/edit /5734b65f5e8cc78d277e63dc?projectName=testing&details=&ammount=&localize=&image=13122913_798137460320744_2366020950260825105_o.jpgブラウザでは、何もデータベースに保存されません –
'project'は' null'ではありませんか? –