Permalink
Browse files

Update to include compute avg rating in show.ejs

  • Loading branch information...
jim-clark
jim-clark committed Feb 9, 2019
1 parent 8dc89f8 commit 4aeb0f40a3c9b50cb827c87433415dd3331a5b92
@@ -1,7 +1,7 @@

[click here to view as a presentation](https://presentations.generalassemb.ly/5a3ff8eeef72ad1a3c53986c2784ee67#/1)

<style style="visibility:hidden"> .reveal li {font-size: 32px;} .reveal ul ul li, .reveal ul ol li, .reveal ol ol li, .reveal ol ul li { font-size: 28px; } </style>
<link href="https://gist.githubusercontent.com/jim-clark/6919052ab15de680c120907d223c31b5/raw/9eedb5e3c01352b9ccda7264227f253be56a08b7/slide.css">

---

@@ -56,11 +56,11 @@
#### Review the Starter Code
<br>

- Today's starter code is the final code from yesterday's _Mongoose - Embedding Related Data_ lesson with one significant refactor...
- Today's starter code is the final code from yesterday's _Mongoose - Embedding Related Data_ lesson with a couple of changes...

- The `cast` property on the `Movie` model has been removed and all related forms/views and controller code have been adjusted accordingly.
- The `cast` property on the `Movie` model has been removed and all related forms/views and controller code have been adjusted accordingly. This was done so that in this lesson we can reference _performer_ documents created using a `Performer` Model.

- Instead, during this lesson we'll learn how to reference _performer_ documents created using a `Performer` Model.
- The **movies/show.ejs** view shows how you can use EJS to calculate an _average rating_ for a movie.

---
#### Perform CRUD Using<br>Mongoose Models in a Node REPL
@@ -50,13 +50,19 @@
</tr>
</thead>
<tbody>
<% var total = 0 %>
<% movie.reviews.forEach(function(r) { %>
<% total += r.rating %>
<tr>
<td><%= r.createdAt.toLocaleDateString() %></td>
<td><%= r.content %></td>
<td><%= r.rating %></td>
</tr>
<% }); %>
<% }); %>
<tr>
<td colspan="2"></td>
<td><strong><%= (total / movie.reviews.length).toFixed(1) %></strong></td>
</tr>
</tbody>
</table>
<% } else { %>
@@ -11,9 +11,9 @@
<div><%= movie.nowShowing ? 'Yes' : 'Nope' %></div>
</section>

<br><br><h2>Reviews</h2>
<form id="add-review-form" method="POST"
action="/movies/<%= movie._id %>/reviews">
<br><br>
<h2>Reviews</h2>
<form id="add-review-form" method="POST" action="/movies/<%= movie._id %>/reviews">
<label>Review:</label>
<textarea name="content"></textarea>
<label>Rating:</label>
@@ -31,19 +31,25 @@
<table>
<thead>
<tr>
<th>Date</th>
<th>Date</th>
<th>Review</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
<% var total = 0 %>
<% movie.reviews.forEach(function(r) { %>
<% total += r.rating %>
<tr>
<td><%= r.createdAt.toLocaleDateString() %></td>
<td><%= r.content %></td>
<td><%= r.rating %></td>
</tr>
<% }); %>
<tr>
<td colspan="2"></td>
<td><strong><%= (total / movie.reviews.length).toFixed(1) %></strong></td>
</tr>
</tbody>
</table>
<% } else { %>

0 comments on commit 4aeb0f4

Please sign in to comment.