Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TypeError: C:UsersUSERRealtime-Chatplayground-loginviewsindex.pug:3
- 1| extends layout
- 2| block content
- > 3| if registrations.length
- 4| table
- 5| tr
- 6| th Name
- Cannot read property 'length' of undefined
- [...]
- at router.get (C:UsersUSERRealtime-Chatplayground-loginroutesindex.js:33:7)
- [...]
- const mongoose = require('mongoose');
- const Schema = mongoose.Schema;
- const registrationSchema = new Schema({
- //[...]
- });
- module.exports = mongoose.model('Registration', registrationSchema);
- //[...]
- const Registration = require('../models/Registration');
- //[...]
- router.post('/', [{...}], (req, res) => {
- //NR1
- const errors = validationResult(req);
- if(errors.isEmpty()) {
- //NR2
- const registration = new Registration(req.body);
- registration.save()
- .then(() => {res.send('Thanks for your registration!')})
- .catch(() => {res.send('Sorry! Something went wrong.')})
- } else {
- res.render('form', {
- title: 'Registration form',
- errors: errors.array(),
- data: req.body
- });
- //NR3
- };
- });
- router.get('/registrations', (req, res) => {
- Registration.find()
- .then((registrations) => {
- res.render('index', {title: 'Listing registrations', registrations})})
- .catch(() => {res.send('Sorry! Something went wrong.')});
- })
- //[...]
- extends layout
- block content
- if registrations
- table
- tr
- th Name
- th Email
- each registration in registrations
- tr
- td= registrations.name
- td= registrations.email
- else
- p No registrations yet :(
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement