Last active
September 11, 2015 00:33
-
-
Save suissa/541b5d3811433a6ce792 to your computer and use it in GitHub Desktop.
Exemplo de como usar o method-override para enviar um FORM com POSt e ele mudar para PUT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var methodOverride = require('method-override'); | |
// Method Override | |
app.use(methodOverride(function(req, res){ | |
if (req.body && typeof req.body === 'object' && '_method' in req.body) { | |
// look in urlencoded POST bodies and delete it | |
var method = req.body._method | |
delete req.body._method | |
return method | |
} | |
})); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
form(method='POST', action='/api/beers/#{beer._id}') | |
.form-group | |
label(for='name') Name: | |
input(type='text', name='name', value='#{beer.name}') | |
.form-group | |
label(for='price') Price: | |
input(type='text', name='price', value='#{beer.price}') | |
.form-group | |
label(for='alcohol') Alcohol: | |
input(type='text', name='alcohol', value='#{beer.alcohol}') | |
.form-group | |
label(for='category') Category: | |
input(type='text', name='category', value='#{beer.category}') | |
.form-group | |
label(for='description') Description: | |
textarea(name='description') #{beer.description} | |
.form-group | |
input(type='submit', value='ALETERAR') | |
input(type='hidden', name='_method', value='PUT') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment