//评论编辑路线
router.get("/campgrounds/:id/comments/:comment_id/edit", function(req,res){
Comment.findById(req.params.comment_id , function(err,foundComment){
if(err){
res.redirect("back");
} else{
res.render("comments/edit.ejs",{campground_id :req.params.id ,
comment:foundComment});
}
});
});
//评论更新路线
router.put("/campgrounds/:id/comments/:comment_id",function(req,res){
Comment.findByIdAndUpdate( req.params.comment_id, req.body.comment ,
function(err,updatedComment){
if(err){
res.redirect("back");
}else{
res.redirect("/campgrounds/" + req.params.id);
}
ejs文件是
<form action="/campgrounds/<%= campground_id %>/comments/<%=comment._id%>?
_method=PUT" method="POST">
<div class="container">
<input type="text" name="comment[text]" value="<%=comment.text%>">
<button>Submit</button>
</div>
</form>
我无法编辑评论并进行更新,在此先感谢:)
这是评论模型代码
var mongoose= require("mongoose");
var commentSchema=new mongoose.Schema(
{ text: String,
author: { id: { type:mongoose.Schema.Types.ObjectId, ref: "User" },
username: String }
});
module.exports=mongoose.model("Comment",commentSchema);
答案 0 :(得分:0)
我认为你需要添加一些空格:
<%=comment.text%>
到
<%= comment.text %>