Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 73905

Argument passed in must be a single String of 12 bytes or a string of 24 hex characters

$
0
0

I want to update the mongodb database using PUT Method. I installed method-override and included, but am still getting an error:

Argument passed in must be a single String of 12 bytes or a string of 24 hex characters.

The code is below:

//UPDATE ROUTE 
app.put("/blogs/:id", function(req, res){
   //let id = req.params.id;
   //let newData = req.body.blog;
   Blog.findByIdAndUpdate(req.params.id, req.body.blog, function(err, updatedBlog){
      if (err){
         console.log(err);
         //res.redirect("/blogs");
      } else {
         res.redirect("/blogs/" + id);
      }
   });
});

the ejs file

<%- include('partials/header'); -%>

    <div class="ui main text container segment" style="margin-top: 7.0em;">
       <div class="ui huge header">Edit <%= blog.title %> </div>
       <!--HTML does not support PUT request, we have to use 
       Method-Override by adding ?_method=PUT-->
       <form class="ui form" action="/blogs/ <%= blog._id %>?_method=PUT" method="POST">
          <div class="field">
             <label for=""><Title></Title></label>
             <!--Using value attribute instead of placehold to retrieve the data from the database-->
             <input type="text" name="blog[title]" value="<%= blog.title %>">
          </div>
          <div class="field">
             <label for="">Blog Image</label>
             <input type="text" name="blog[image]" value="<%= blog.image %>">
          </div>
          <div class="field">
             <label for="">Blog Content</label>
             <textarea name="blog[body]" id="" cols="30" rows="10"> <%= blog.body %></textarea>
          </div>
          <input class="ui violet basic button" type="submit">
       </form>
    </div>


    <%- include('partials/footer'); -%>

Viewing all articles
Browse latest Browse all 73905

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>