by Ian Schoonover
We'll be adding a cost input to the new campground form:
Add cost property
var mongoose = require("mongoose");
var campgroundSchema = new mongoose.Schema({
name: String,
image: String,
description: String,
cost: Number,
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String
},
comments: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Comment"
}
]
});
module.exports = mongoose.model("Campground", campgroundSchema);
<div class="form-group">
<input class="form-control" type="number" name="cost" placeholder="cost" step="0.01" min="0" required>
</div>
<div class="form-group">
<input class="form-control" type="number" name="cost" value="<%= campground.cost %>" step="0.01" min="0" required>
</div>
var cost = req.body.cost;
var newCampground = {name: name, image: image, cost: cost, description: desc, author:author};
var newData = {name: req.body.name, image: req.body.image, cost: req.body.cost, description: req.body.description};
<h4 class="pull-right">$9.00/night</h4>
with this:
<h4 class="pull-right">$<%= campground.cost %>/night</h4>
Congratulations! Your YelpCamp app now has a dynamic pricing feature
If you have any questions then please create a thread in the Q&A