İş İlanını Düzenle

// APP.JS
app.get("/:postId/duzenle", (req, res, next) => {
  const postId = req.params.postId; Post.findById(postId, function(err, foundPost) { res.render("duzenle", {post: foundPost})})
})

app.post("/:postId/duzenle", function(req, res) {
	const postId = req.params.postId
	Post.findById(postId, function(err, foundPost) {foundPost.title = req.body.title; foundPost.content = req.body.content; foundPost.save() })

  res.redirect("/posts/" + postId)
})
// EJS View
<%- include("partials/header") -%>
<%- include("partials/navbar") -%>

<div class="container">
  <div class="col-md-8 mx-auto mt-5">
    <div class="card">
        <h5 class="card-header">Postu Düzenle</h5>
        <div class="card-body">

            <form action="/<%= post.id %>/duzenle" method="POST">

                <div class="form-group">
                    <label for="title">Title</label>
                    <input class="form-control" type="text" name="title" value="<%= post.title  %>"">
                </div>

                <div class="form-group">
                    <label for="postContent">Content</label>
                    <input class="form-control" type="text" name="content"  value="<%= post.content  %>">
                </div>

                <button type="submit" class="btn btn-danger btn-block">Düzenle</button>
            </form>

        </div>
    </div>
  </div>
</div>

<%- include("partials/footer") -%>

Last updated