没有路线匹配?

时间:2017-10-04 13:18:42

标签: ruby-on-rails rspec rspec-rails rails-routing rails-api

我的一个测试(并使用命令行中的curl)我的一个路由(POST / users / confirm)中出现“No route matches”异常。我试过的卷曲如下,它们都不起作用,并且收到下面注释中列出的相同例外情况:

curl -X POST -H "Content-Type: application/json; version=1" \
   -d '{ user: { "token":"1deb36b4e6a7ba6d9203" } }' \
   http://localhost:3000/appname/users/confirm

curl -X POST -H "Content-Type: application/json; version=1" \
   -d '{ "token":"1deb36b4e6a7ba6d9203" }' \
   http://localhost:3000/appname/users/confirm

enter image description here

我的测试如下。我的/config/application.rb文件中有config.wrap_parameters = true ...

enter image description here

这是我的User UsersController#确认动作以及我强大的参数。我params.require(:user).permit(:token)而不是简单params.permit(:token),因为如上所述,我的/config/application.rb文件中有config.wrap_parameters = true ...

enter image description here

这是我的路线入口......

enter image description here

以下是rails routes的输出(删除了应用名称)...

enter image description here

我的/config/application.rb文件中有config.wrap_parameters = true ...

enter image description here

奇怪的是,如果我将测试中的参数更改为post :confirm, params: { token: @user.confirmation_token },我会收到以下错误: enter image description here

不知所措。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

事实证明我不需要:我的路线中的令牌。将其更改为此,一切顺利:

将'/ appname / users / confirm /'发布到:'users#confirm',as:'appname_users_confirm'

相关问题