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

resources 路由进不去update方法 #3360

Closed
callmesoul opened this issue Jan 3, 2019 · 10 comments
Closed

resources 路由进不去update方法 #3360

callmesoul opened this issue Jan 3, 2019 · 10 comments

Comments

@callmesoul
Copy link

callmesoul commented Jan 3, 2019

路由注册:
router.resources('express', '/api/express', controller.express);
controller->express:

const Controller = require('egg').Controller;

class HomeController extends Controller {
    async index(ctx) {
        ctx.body='dasd';

    }

    async create(ctx) {
        ctx.body='dasd';
    }

    async show(ctx) {
        ctx.body='dasd';
    }

    async update(ctx) {
        ctx.body='dasd';
    }

    async destroy(ctx) {
        ctx.body='dasd';
    }
}

module.exports = HomeController;
Request URL:http://127.0.0.1:7001/api/pets/1
Request Method:POST
Status Code:404 Not Found
Remote Address:127.0.0.1:7001
Referrer Policy:no-referrer-when-downgrade

其他方法都可以,就update 404,也打印不了

其他resources试了也是一样,都行就update 404 进不去

@egg-bot
Copy link

egg-bot commented Jan 3, 2019

Hello @callmesoul. Please provide a reproducible example following the instruction.

Issues labeled by Need Reproduce will be closed if no activities in 7 days.


@callmesoul,请根据这个说明提供最小可复现代码。

如果在 7 天内没有进展会被自动关闭。

@callmesoul
Copy link
Author

callmesoul commented Jan 3, 2019

@egg-bot
直接用 egg-init egg-example --type=simple
添加路由 router.resources('pets', '/api/pets', controller.pets);
添加pets controller:

'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    this.ctx.body = '416546546';
  }
  async update(ctx) {
    ctx.body = 123456;
  }
}

module.exports = HomeController;

config.default.js 关闭csrf:

config.security= {
        csrf: {
            enable: false,
        }
    };

再使用postman
post http://127.0.0.1:7001/api/pets/1
结果404

PS F:\egg-example> egg-init --version
1.15.0

@atian25
Copy link
Member

atian25 commented Jan 3, 2019

@callmesoul

#3310

尤其是最后一项『最小可复现仓库』 ,请通过 npx egg-init --type=simple 来初始化并 上传到你的 GitHub 仓库。

@callmesoul
Copy link
Author

@atian25
Copy link
Member

atian25 commented Jan 3, 2019

@atian25 atian25 closed this as completed Jan 3, 2019
@callmesoul
Copy link
Author

看错了不好意思,
我记得以前好像也是post的啊

@atian25
Copy link
Member

atian25 commented Jan 3, 2019

这个一直没改过。

@callmesoul
Copy link
Author

好吧...

@yangjindong
Copy link

目前也碰到进不了update方法的问题。使用Form表单更新数据的时候,设置method="PATCH",但直接跳转到show方法了。
https://github.com/yangjindong/egg-example

@yangjindong
Copy link

yangjindong commented Jan 6, 2020

经过查看Rails的form_for文档,发现需要在form表单里,添加

<input type="hidden" name="_method" value="patch" />

原method还是直接按照method="post"设置

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

No branches or pull requests

4 participants