Sunday, 11 June 2017

Cannot read property 'forEach' of undefined node.js

I am getting a .forEach() error on this code

```<% if(locals.isAuthenticated) { %>
  <section>
    <h4>Leave a comment</h4>
    <form method="POST" action="/landmarks/<%= landmark.id %>/comments">
      <textarea name="content" id="content" placeholder="Comment"></textarea>
      <button class="button">Leave a comment</button>
    </form>
  </section>
<% } %>

<section>
  <h4>Comments</h4>
  <% landmark.comments.forEach((comment) => { %>
    <p><%= comment.content %></p>
    <small><%= comment.createdBy.username %></small>
    <small><%= comment.createdAt.toDateString() %></small>

    <% if(locals.isAuthenticated && comment.belongsTo(user)) { %>
      <form method="POST" action="/landmarks/<%= landmark.id %>/comments/<%= comment.id %>">
        <input type="hidden" name="_method" value="DELETE">
        <button class="btn">Delete Comment</button>
      </form>
    <% } %>
  <% }) %>
</section>```

I am unsure why this is happening as I i believe this is correct syntax for the forEach method



via James Clarke

No comments:

Post a Comment