Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. TypeError: C:UsersUSERRealtime-Chatplayground-loginviewsindex.pug:3
  2. 1| extends layout
  3. 2| block content
  4. > 3| if registrations.length
  5. 4| table
  6. 5| tr
  7. 6| th Name
  8. Cannot read property 'length' of undefined
  9. [...]
  10. at router.get (C:UsersUSERRealtime-Chatplayground-loginroutesindex.js:33:7)
  11. [...]
  12.  
  13. const mongoose = require('mongoose');
  14. const Schema = mongoose.Schema;
  15. const registrationSchema = new Schema({
  16. //[...]
  17. });
  18. module.exports = mongoose.model('Registration', registrationSchema);
  19.  
  20. //[...]
  21. const Registration = require('../models/Registration');
  22. //[...]
  23. router.post('/', [{...}], (req, res) => {
  24. //NR1
  25. const errors = validationResult(req);
  26. if(errors.isEmpty()) {
  27. //NR2
  28. const registration = new Registration(req.body);
  29. registration.save()
  30. .then(() => {res.send('Thanks for your registration!')})
  31. .catch(() => {res.send('Sorry! Something went wrong.')})
  32. } else {
  33. res.render('form', {
  34. title: 'Registration form',
  35. errors: errors.array(),
  36. data: req.body
  37. });
  38. //NR3
  39. };
  40. });
  41. router.get('/registrations', (req, res) => {
  42. Registration.find()
  43. .then((registrations) => {
  44. res.render('index', {title: 'Listing registrations', registrations})})
  45. .catch(() => {res.send('Sorry! Something went wrong.')});
  46. })
  47. //[...]
  48.  
  49. extends layout
  50. block content
  51. if registrations
  52. table
  53. tr
  54. th Name
  55. th Email
  56. each registration in registrations
  57. tr
  58. td= registrations.name
  59. td= registrations.email
  60. else
  61. p No registrations yet :(
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement