Closed Dialtor closed 2 years ago
I would start debugging with a very simple forEach
loop, and then slowly add the rest until you figure out what is breaking.
Starting with a very minimal test ensure that EJS itself is working:
(File test.ejs)
<% ['a', 'b', 'c'].forEach((item) => { %>
<p><%= item; %></p>
<% }); %>
In Node repl:
> let ejs = require('./ejs');
undefined
> let tmpl = require('fs').readFileSync('./test.ejs').toString();
undefined
> ejs.render(tmpl);
'\n <p>a</p>\n\n <p>b</p>\n\n <p>c</p>\n\n\n\n'
This should give you enough info to start debugging your app code. This is not a problem with EJS. I am closing this issue. Please feel free to open a new issue if there is a problem with EJS itself.
ROUTES
const router = require('express').Router(); const express = require('express'); const useExpress = express(); const bodyParser = require('body-parser');
useExpress.use(bodyParser.json()); useExpress.use(bodyParser.urlencoded({extended:true}));
const Cliente = require('../models/Clientes'); const Registro = require('../models/Registros');
router.post('/ClientesRegistro', async(req,res) =>{ const newCliente = new Cliente(req.body); await newCliente.save(); res.redirect('/Clientes'); });
module.exports = router;
HTML
<% clientes.forEach((function (cliente)) { %>
I trying use ejs but I can't finish for this :(