title: Edit in Node.js app not working
body: <p>Having some issues with a node app i'm building, the edit button i've attached to the page isn't working (not bringing up the specific entry) i just get a 404 error when I hit edit</p>
  
  <p>stores/index.ejs</p>
  
  <pre><code>&lt;table class="table table-striped"&gt;
          &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Pet Store Name&lt;/th&gt;
              &lt;th&gt;Address&lt;/th&gt;
              &lt;th&gt;Phone Number&lt;/th&gt;
              &lt;th&gt;Website&lt;/th&gt;
          &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
          &lt;!--starting table loop--&gt;
          &lt;% for (var i = 0; i &lt; stores.length; i++) { %&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;%= stores[i].name %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= stores[i].address %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= stores[i].phone %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a href="http://&lt;%= stores[i].website %&gt;"&gt;http://&lt;%= stores[i].website %&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a href="/stores/edit/&lt;%= stores[i]._id %&gt;"&gt;&lt;button class="btn btn-primary"
                                                               type="button"&gt;Edit&lt;/button&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;% } %&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  </code></pre>
  
  <p>edit.ejs</p>
  
  <pre><code> &lt;form method="post" action="&lt;%= stores._id %&gt;"&gt;
          &lt;fieldset class="form-group"&gt;
              &lt;label for="name" class="col-sm-2"&gt;Pet Store Name: &lt;/label&gt;
              &lt;input name="name" id="name" required value="&lt;%= stores.name %&gt;" /&gt;
          &lt;/fieldset&gt;
          &lt;fieldset class="form-group"&gt;
              &lt;label for="address" class="col-sm-2"&gt;Address: *&lt;/label&gt;
              &lt;input name="address" id="address" required value="&lt;%= stores.address %&gt;" /&gt;
          &lt;/fieldset&gt;
          &lt;fieldset class="form-group"&gt;
              &lt;label for="phone" class="col-sm-2"&gt;Phone Number: *&lt;/label&gt;
              &lt;input name="phone" id="phone" value="&lt;%= stores.phone %&gt;" /&gt;
          &lt;/fieldset&gt;
          &lt;fieldset class="form-group"&gt;
              &lt;label for="website" class="col-sm-2"&gt;Website: &lt;/label&gt;
              &lt;input name="website" id="website" value="&lt;%= stores.website %&gt;" /&gt;
          &lt;/fieldset&gt;
          &lt;div&gt;
              &lt;%= stores.created %&gt;
          &lt;/div&gt;
          &lt;button class="btn btn-primary col-sm-offset-2"&gt;Save&lt;/button&gt;
  
          &lt;a href="/stores/delete/&lt;%= stores._id %&gt;" title="Delete" class="confirmation"&gt;
              &lt;button class="btn btn-danger" type="button"&gt;Delete&lt;/button&gt;
          &lt;/a&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>index.js</p>
  
  <pre><code>// link to dependencies
  var express = require('express');
  var router = express.Router();
  var mongoose = require('mongoose');
  var passport = require('passport');
  
  //link to store model
  var Store = require('../models/store');
  
  //set up get handler for password protected store page
  router.get('/', isLoggedIn, function (req, res, next) {
      //use the store model to get directory listing
      Store.find(function (err, stores) {
          if (err) {
              console.log(err);
              res.end(err);
          }
          else {
              //show we got data back, show the view and pass the data through it
              res.render('stores/index', {
                  title: 'Pet Store Directory',
                  stores: stores
              });
          }
      })
  });
  
  // get handler for add to display a blank form
  router.get('/add', isLoggedIn, function (req, res, next) {
      res.render('stores/add', {
          title: 'Add a new Pet Store'
      });
  });
  
  // post handler for adding to the form
  router.post('/add', isLoggedIn, function (req, res, next) {
  
      //save new pet store
      Store.create({
              name: req.body.name,
              address: req.body.address,
              phone: req.body.phone,
              website: req.body.website
          }
      );
  
      // redirect to auth store page
      res.redirect('/stores');
  });
  
  //get handler for edit to show content from entry
  router.get('/id', isLoggedIn, function(req, res, next){
     //create id variable to the store id from the url
      var id = req.params.id;
  
      //look up the selected store
      Store.findById(id, function(err, store){
         if (err) {
             console.log(err);
             res.end(err);
         } 
          else {
             //show edit form
             res.render('stores/edit', {
                title: 'Store Details',
                 store: store
             });
         }
      });
  });
  
  //post handler for edit to update the store
  router.post('/id', isLoggedIn, function(req, res, next){
      //create id variable to the store id from the url
      var id = req.params.id;
  
      //fill the store object
      var store = new Store({
          name: req.body.name,
          address: req.body.address,
          phone: req.body.phone,
          website: req.body.website
      });
  
      //use mongoose and store model to update
      Store.update( {_id: id}, store, function(err){
         if   (err){
             console.log(err);
             res.end(err);
         }
          else {
             res.redirect('/stores')
         }
      });
  });
  
  //get handler for delete using the store id
  router.get('/delete/:id', isLoggedIn, function(req, res, next){
      //get id variable to the store id from the url
      var id = req.params.id;
  
      console.log('trying to delete');
  
      Store.remove({_id: id}, function(err){
         if (err) {
             console.log(err);
             res.end(err);
         }
          else {
             // show updated article list
             res.redirect('/stores');
         }
      });
  });
  
  //authorization check
  function isLoggedIn(req, res, next) {
  
      //is the user authenticated
      if (req.isAuthenticated()){
          return next();
      }
      else {
          res.redirect('/auth/login');
      }
  }
  
  // make public
  module.exports = router;
  </code></pre>
  
  <p>I've poured over the code for hours, it would help to get a fresh set of eyes on it. </p>
  
  <p>github is github.com/krl87/comp2106a2</p>
  
  <p>hosted at comp2106a2.herokuapp.com</p>
  
  <p>thanks in advance!
  kayley</p>