Permalink
Browse files

create delete form

  • Loading branch information...
mekaala committed Feb 14, 2020
1 parent 9a8e84f commit ad6c529de82518193a4d18681eb0c57e96943ad2
Showing with 19 additions and 14 deletions.
  1. +6 −3 controllers/shop.js
  2. +13 −11 views/shops/shop.hbs
@@ -42,7 +42,10 @@ shopRouter.get('/new', (req, res) => {
})

shopRouter.get('/:index', (req,res) => {
res.render('shops/shop', { shop: shopsApi.getShop(index), index } )
res.render('shops/shop', {
shop: shopsApi.getShop(req.params.index),
index: req.params.index
})
})

shopRouter.post('/', (req,res) => {
@@ -52,11 +55,11 @@ shopRouter.post('/', (req,res) => {

shopRouter.put('/:index', function(req,res){
shopsApi.updateShop(req.params.index, req.body);
res.status(200).end();
res.redirect('/shops')
})

shopRouter.delete('/:index', function(req,res){
shopsApi.deleteShop(req.params.index);
shopsApi.deleteShop(req.params.index, req.body);
res.redirect('/shops');
})

@@ -1,15 +1,17 @@
<form method="POST" action="/shops?_method=PUT">
<form action="/shops/{{ index }}?_method=PUT" method="POST">

<!--
Template for creating input form for a string object key called stringMember
NOTE: for numeric input fields use `type="number"`
-->
<input type="text" value="{{ shop.name }}" name="name" />
Name: <input type="text" name="name" value="{{ shop.name }}" />

<!--
Template for creating input form for a boolean object member
-->
<input type="checkbox" name="currentlyOpen" value="true" {{#if shop.currentlyOpen }}checked{{/if}} />
Employees: <input type="number" name="employee" value="{{ shop.employees }}"/>

Open: <input type="checkbox" name="currentlyOpen" {{#if shop.currentlyOpen }}checked{{/if}} />

<input type="submit" value="Update Shop" />

</form>

<form action= "/shops/{{ index }}?_method=DELETE" method="POST">

<input type="submit" value="Delete Shop" />

<input type="submit" value="Update Shop" />
</form>

0 comments on commit ad6c529

Please sign in to comment.