0

I'm trying to create a CRUD app using Node and express, i'm relatively new to it. I have an ideas page and an edit button on each idea. I keep on getting the error "Cannot GET /ideas/edit1/" when I click the edit button(this view exists by the way).

Here's the code I used to edit data in a form:

app.get('/ideas/edit/:id', (req, res) => {
    Idea.findOne({
            _ id: req.params.id
        })
        .then(idea => {
            res.render('ideas/edit1', {
                idea: idea
            });
        });

})

I have checked the express documentation and i'm pretty sure express uses the : to denote a variable in a route.

I'm wondering what else to do.

Augustin
  • 15
  • 3

2 Answers2

1

Instead of res.render('ideas/edit1' you should be using res.render('ideas/edit/1')

  • if you can tell me, what are you trying to achieve here, maybe I can help you out. –  May 17 '20 at 09:48
  • Otherwise, you can dynamically generate pages using your template engine like EJS. –  May 17 '20 at 09:49
  • Puneet Chandiok: I'm trying to make edit existing posts using an edit form. I'm trying to get the id of each post dynamically from the url to edit that particular post – Augustin May 17 '20 at 09:53
0

Check your form, maybe you are not passing the id correctly.