title: Convert form select box from .pug to .ejs
body: <p>I'm trying to convert the below from pug to ejs. It's a select box of authors (from an associated collection) in a form to add a book to the db. It throws error "Cannot read property '_id' of undefined" pointing to the first option element when I add a new book (but I can update an existing book for some reason). And in the pug version it doesn't throw this error. Is my conversion right?</p>
  
  <pre><code>select#author.form-control(type='select', placeholder='Select author' name='author' required='true' )
    - authors.sort(function(a, b) {let textA = a.family_name.toUpperCase(); let textB = b.family_name.toUpperCase(); return (textA &lt; textB) ? -1 : (textA &gt; textB) ? 1 : 0;});
    for author in authors
      if book
        option(value=author._id selected=(author._id.toString()==book.author._id.toString() ? 'selected' : false) ) #{author.name}
      else
        option(value=author._id) #{author.name}
  </code></pre>
  
  <p>My conversion:</p>
  
  <pre><code>&lt;select class="form-control" id="author" type="select" placeholder="Select author" name="author" required="true"&gt;
    &lt;% authors.sort(function(a, b) {let textA = a.family_name.toUpperCase(); let textB = b.family_name.toUpperCase(); return (textA &lt; textB) ? -1 : (textA &gt; textB) ? 1 : 0;}); %&gt;
    &lt;% authors.forEach(function(author) { %&gt;
      &lt;% if(typeof book !== 'undefined') { %&gt;
        &lt;option value="&lt;%= author._id %&gt;" selected=&lt;%= (author._id.toString() == book.author._id.toString()) ? 'selected' : 'false' %&gt;&gt;&lt;%= author.name %&gt;&lt;/option&gt;
      &lt;% } else { %&gt;
        &lt;option value="&lt;% author._id %&gt;"&gt;&lt;%= author.name %&gt;&lt;/option&gt;
      &lt;% } %&gt;
    &lt;% }) %&gt;
  &lt;/select&gt;
  </code></pre>