안녕하세요. 강의 잘 듣고 있습니다.
/edit 으로 접속해서 글들을 수정하고 다시 서브밋해도 /list에서 변경이 되지 않습니다.
Cosnsole 에서는 오류는 안나고 수정완료라는 메세지는 뜨는데 기능은 안되는데.. 제눈엔 뭐가 문제인지 찾아봐도 모르겠습니다.
<form action="/edit?_method=PUT" method="POST">
<div class="form-group">
<label>오늘의 할일</label>
<input
type="text"
name="id"
style="display: none"
value="<%= post.id %>"
/>
<input
value="<%= post.제목 %>"
type="text"
class="form-control"
name="title"
/>
</div>
<div class="form-group">
<label>날짜</label>
<input
value="<%= post.날짜 %>"
type="text"
class="form-control"
name="date"
/>
</div>
<button type="submit" class="btn btn-danger mt-2">Submit</button>
</form>
------------------------------------------------------------------------------------
app.get("/edit/:id", (req, res) => {
db.collection("post").findOne(
{ _id: parseInt(req.params.id) },
(error, result) => {
console.log(result);
res.render("edit.ejs", { post: result });
}
);
});
app.put("/edit", (req, res) => {
db.collection("post").updateOne(
{ _id: parseInt(req.body.id) },
{ $set: { 제목: req.body.title, 날짜: req.body.date } },
(error, result) => {
console.log("수정완료");
res.redirect("/list");
}
);
});