Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda