Chinmay Bapna
Chinmay Bapna

Reputation: 67

put route not working in node.js showing error cannot PUT

put route is not working in the following code . I have installed method-override too . I can't find the error in my code .this is the error I am getting : Cannot PUT /blogs/5dc41f2e1c5eb907574a24db

//UPDATE route
 app.put("/blog/:id", function(req, res) {
     Blog.findByIdAndUpdate(req.params.id, req.body.blog, function(err, updatedBlog) {
     if(err) {
        res.send("ERROR!");
     } else {
     res.redirect("/blogs/"+req.params.id);
     }
     });
 });

// FORM 
    <% include ./partials/header %>

    <div class="container form_container">
        <h1 class="form_heading">
            EDIT <%=blog.title%>
        </h1>
        <form action="/blogs/<%=blog._id%>?_method=PUT" method="POST" class="form">
            <div class="form_group">
                <label>Title:</label>
                <input class="form-control" type="text" name="blog[title]" placeholder="title" value="<%=blog.title%>">
            </div>
            <div class="form_group">
                <label>Image:</label>
                <input class="form-control" type="text" name="blog[image]" placeholder="image"  value="<%=blog.image%>">
            </div>
            <div class="form_group">
                <label>Content:</label>
                <textarea class="form-control" name="blog[body]" placeholder="your post goes here ..." rows="5"><%=blog.body%></textarea>
            </div>
            <button type="submit" class="btn btn-primary btn-lg">Submit</button>
        </form>`enter code here`
    </div>

    <% include ./partials/footer %>

Upvotes: 0

Views: 145

Answers (1)

LostJon
LostJon

Reputation: 2387

you have blog in your PUT path but your request is to blogs

Upvotes: 1

Related Questions