New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update form mixin, fixes #3
Conversation
src/index.js
Outdated
@@ -33,6 +33,10 @@ export default () => { | |||
await next(); | |||
}); | |||
app.use(bodyParser()); | |||
app.use(async (ctx, next) => { | |||
ctx.request.body = { ...ctx.request.body, ...ctx.request.query }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вот так нельзя делать, body может быть чем угодно, в том числе бинарными данными
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тогда необходимо переписать следующую миддлвару, где if (req.body && typeof req.body === 'object' && '_method' in req.body)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (req.body && typeof req.body === 'object' && '_method' in req.query) {
// eslint-disable-next-line
return req.query._method;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
проблема в том что ты отправляешь _method в query, а его надо отправлять в body
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
генерируя скрытый элемент формы (посмотри на хекслете форму редактирования аккаунта)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
понял, добавить: <input type="hidden" name="_method" value="patch">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
обновил миксин и реквест
thanks! |
Миксин для формы:
mixin formFor(f, options = { <url>, <method> })
Если метод
get || post
, то создается обычная форма;Если другой метод, то
method="post"
, аaction=<url>?_method=<method>
index.js
Добавил миддлвару. Без нее
bodyParser
не добавляет вctx.request.body
параметры изctx.request.query
(необходимо для передачи_method
)DEBUG=
в Makefile:
DEBUG="application:*"
, а в logger.js былоconst log = debug('app');