I'm new to Express/Node/Mongo and trying to build an assets database application to store fixed assets.
I'm trying to save the fixed asset data through the web form but only the ID is being created for some reason and the actual data from the form is not saving.
I've looked at the data in my mongo container and can only see an ID for each asset I've created
Here is my route...
/* POST create fixed-assets page. */
router.post('/financial/assets/create-fixed-asset', secured(), function(req, res, next) {
var assetData = {
model_number: req.body.model_number,
manufacturer: req.body.manufacturer,
description: req.body.description,
serial_number: req.body.serial_number,
asset_tag_number: req.body.asset_tag_number,
condition_when_purchased: req.body.condition_when_purchased,
price_paid: req.body.price_paid
};
FixedAsset.create(assetData, function (error, asset) {
if (error) {
return next(error);
} else {
res.redirect('/financial/assets/fixed-assets');
}
});
});
Here is my list view...(using Pug/Jade)
block view
.animated.fadeIn
h1 Fixed Assets
a(href='create-fixed-asset/') Create
br
br
table#example.display
thead
tr
th ID
th Model
th Description
tbody
each asset in assets
tr
td #{asset.id}
td #{asset.model_number}
td #{asset.manufacturer}
Here is my mongoose model...
var mongoose = require('mongoose');
var FixedAssetSchema = new mongoose.Schema({
model_number: {
type: String
},
manufacturer: {
type: String
},
description: {
type: String
},
serial_number: {
type: String
},
asset_tag_number: {
type: Number
},
condition_when_purchased: {
type: String
},
price_paid: {
type: Number
}
});
var FixedAsset = mongoose.model('FixedAsset', FixedAssetSchema);
module.exports = FixedAsset;
Does anyone see why this is happening? Thanks
Edit: Also I forgot to put the code for my Pug form. Here it is...
extends /default
block scripts
if !starter
// Plugins and scripts required by this view
script(src='/js/main.js')
block view
.animated.fadeIn
.container.row
.col-md-6
h1 #{title}
.container.row
.col-md-6
form(method='POST' action='/financial/assets/create-fixed-asset')
div.form-group
input#model_number.form-control(type='text', placeholder='Model Number')
div.form-group
input#manufacturer.form-control(type='text', placeholder='Manufacturer')
div.form-group
input#serial_number.form-control(type='text', placeholder='Serial Number')
div.form-group
input#description.form-control(type='text', placeholder='Description')
div.form-group
input#asset_tag_number.form-control(type='text', placeholder='Asset Tag Number')
div.form-group
input#condition_when_purchased.form-control(type='text', placeholder='Condition When Purchased')
div.form-group
input#price_paid.form-control(type='text', placeholder='Price Paid')
br
button.btn.btn-success(type='submit') Create