Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
Put request edits not updating object in database but no error either

My database has 'artists' that I can create & delete, but have suddenly lost the ability to edit them. Every other request type works and even when I submit the edit, the routes don't show errors and I'm redirected to the proper page so I suspect it has something to do with my form submission.

I've included my two edit requests below (get and put) from my routes-> artists.js, as well as my delete request since that one is working just fine.

router.get('/:id', catchAsync(async(req, res,) => {
    const artist = await Artist.findById(req.params.id);
    if (!artist) {
        req.flash('error', 'Cannot find that Artist');
        return res.redirect('/artists');
    }
    res.render('artists/show', { artist });
}));

/* artist edits form*/
router.get('/:id/edit', catchAsync(async (req, res) => {
    const artist = await Artist.findById(req.params.id);
    if (!artist) {
        req.flash('error', 'Cannot find that Artist');
        return res.redirect('/artists');
    }
    res.render('artists/edit', { artist }); 
}))

router.put('/:id', catchAsync(async (req, res) => {
    const { id } = req.params;
    const artist = await Artist.findByIdAndUpdate(id, { ...req.body.artist });
    res.redirect(`/artists/${artist._id}`);
}))

Here's the form to update username:

<% layout('layouts/boilerplate')%>
<div class="row">
    <h1 class="text-center">Edit Artist</h1>
    <div class="col-md-6 offset-md-3">
        <form action="/artists/<%=artist._id%>?_method=PUT" method="POST" novalidate class="validated-form"
            enctype="multipart/form-data">
            <div class="mb-3">
                <label class="form-label" for="artist[username]">Title</label>
                <input class="form-control" type="text" id="username" name="username"
                    value="<%= artist.username %>" required>
                <div class="valid-feedback">
                    Looks good!
                </div>
            </div>
            <div class="mb-3">
                <button class="btn btn-primary">Update artist</button>
            </div>
        </form>
        <a href="/artists/<%= artist._id%>">Back To artist</a>
    </div>
</div>

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda