Open ezeloop opened 4 years ago
you need to edit secrets.ejs
edit secrets.ejs with <% usersWithSecrets.forEach(function(ele){ %>
<%= ele.secret%>
<%} %>
Same problem with me. First of all, it is not saving input (secret) into DB, that's why it is not rendering secrets. I copied the code from here, but no change. Tried restarting DB and so on. Any idea why?
I copied the code from here, but no change. Tried restarting DB and so on. Any idea why?
I guess you forgot to add submit post route:
app.post("/submit", function(req, res) {
const submittedSecret = req.body.secret;
User.findById(req.user.id, function(err, foundUser) {
if (err) {
console.log(err);
} else {
if (foundUser) {
foundUser.secret = submittedSecret;
foundUser.save(function() {
res.redirect("/secrets");
});
}
}
});
});
Have you update your user schema i.e add secrets: String in user schema?
I am updated the userschema & also added the submit post route code but it's still not working.. how can I fix this secret route problem that can loop through all my secrets ??? plz help me
req.user._id
Use this in submit post request, it will work!
req.user._id
Use this in submit post request, it will work!
Hey! I tried all of the things but none worked for me:( my code is exactly the same as Angela.
Hey!! did u manage to solve the issue? I am facing exactly the same issue. But i have an extra issue.. my secret isnt even getting saved in the db.
it is deprecated, and dont know how to write them now
I have all the code like the posted one, and it doesnt appear the secrets!
app.get("/secrets", function(req, res){ User.find({"secret": {$ne: null}}, function(err, foundUsers){ if (err){ console.log(err); } else { if (foundUsers) { res.render("secrets", {usersWithSecrets: foundUsers}); } } }); });
in the db i have the secret, but i cant show them!