Skip to content
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

Merged
merged 1 commit into from Aug 14, 2017
Merged

Conversation

vishenkov
Copy link
Contributor

@vishenkov vishenkov commented Aug 14, 2017

Миксин для формы:
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');

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 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот так нельзя делать, body может быть чем угодно, в том числе бинарными данными

Copy link
Contributor Author

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) ?

Copy link
Contributor Author

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;
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

проблема в том что ты отправляешь _method в query, а его надо отправлять в body

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

генерируя скрытый элемент формы (посмотри на хекслете форму редактирования аккаунта)

Copy link
Contributor Author

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">

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

обновил миксин и реквест

@mokevnin mokevnin merged commit b64f89e into hexlet-boilerplates:master Aug 14, 2017
@mokevnin
Copy link
Contributor

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants