Correct Review
Correct Review
#### ROUTE/REVIEW.JS
Make sure the route includes the `id` parameter for the listing.
```javascript
const express = require("express");
const router = express.Router({ mergeParams: true }); // Ensure access to parent
route params
const wrapAsync = require("../utils/wrapAsync.js");
const { validateReview, isLoggedIn } = require("../middleware.js");
const reviewController = require("../controllers/review.js");
module.exports = router;
```
#### CONTROLLER/REVIEW.JS
Ensure you use the correct syntax for the `Listing` model and access the
`req.params.id` correctly.
```javascript
const Listing = require('../models/listing.js');
const Review = require("../models/review.js");
listing.reviews.push(newReview);
await newReview.save();
await listing.save();
```javascript
const reviewRoutes = require('./routes/review');
// Listings Routes
app.use('/listings/:id/reviews', reviewRoutes);
```
#### SHOW.EJS
Make sure the form action includes the correct listing ID to pass it to the route.
```html
<form action="/listings/<%= listing._id %>/reviews" method="POST" novalidate
class="needs-validation">
<div class="mb-3 mt-3">
<label for="rating" class="form-label">Rating</label>
<fieldset class="starability-slot">
<input type="radio" id="no-rate" class="input-no-rate"
name="review[rating]" value="0" checked aria-label="No rating." />
<input type="radio" id="first-rate1" name="review[rating]" value="1" />
<label for="first-rate1" title="Terrible">1 star</label>
<input type="radio" id="first-rate2" name="review[rating]" value="2" />
<label for="first-rate2" title="Not good">2 stars</label>
<input type="radio" id="first-rate3" name="review[rating]" value="3" />
<label for="first-rate3" title="Average">3 stars</label>
<input type="radio" id="first-rate4" name="review[rating]" value="4" />
<label for="first-rate4" title="Very good">4 stars</label>
<input type="radio" id="first-rate5" name="review[rating]" value="5" />
<label for="first-rate5" title="Amazing">5 stars</label>
</fieldset>
</div>
<div class="mb-3 mt-3">
<label for="comment" class="form-label">Comments</label>
<textarea name="review[comment]" id="comment" cols="100" rows="7"
class="form-control" required></textarea>
<div class="invalid-feedback">Please submit some comments for the
review</div>
</div>
<button class="btn btn-outline-dark">Submit</button>
</form>
```
#### MODEL/REVIEW.JS
No change is required here, but ensure proper casing in your schema (`comment`
instead of `Comment`):
```javascript
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
---