CRUD – create data
Now we're going to take what we've just learned, and use it to add the ability to create users in our application. If we look back to the routes we set up in app.js
, we can see that we have two routes for creating a user, the form itself and the form action.
app.get('/user/new', user.create); // Create new user form app.post('/user/new', user.doCreate); // Create new user action
Adding a new user form
To display the form in an HTML page, we need to do two things:
Create the Jade template
Link the template to the route
Adding the Jade template
By default Express will install with two Jade template files, layout.jade
and index.jade
. The layout template contains the HTML skeleton, including the DTD
, <head>
, and <body>
tags. The index template extends the layout template inside the <body>
tag.
For our MongoosePM application, we will keep this simple approach, and create a new extension template for each new page template we need. This is a great approach for...