ruby-on-rails - APIpie 接收整数参数作为字符串
问题描述
我有以下 RSpec 测试:
it 'should not list alerts, since I do not have access to this model' do
get :index, params: { model_id: @model2.id, workspace_id: @workspace.id }, as: :json
expect(response).to have_http_status(:forbidden)
end
它失败了,因为 Apipie 抱怨workspace_id
它实际上不是一个字符串,它是一个整数。我调试了电话,检查了@workspace
,id
绝对是一个整数。
我现在正在将应用程序迁移到 Rails 5.2.0(以前的 Rails 4)时看到了这个问题。
有没有人见过这样的东西?
解决方案
当GET
您尝试发送一些有效负载时,请求不包含正文。在GET
请求的情况下,所有参数都作为 url 查询(例如/index?model_id=1&workspace_id=1
)传递,并且所有参数都是字符串。
您在这里有两个选择:
- 更改
GET
为POST
,它将允许带有正文的请求。 - 在操作中将字符串转换为整数。
推荐阅读
- dataframe - 替换数据框中的值
- java - 结合ArrayList
和数组列表 一个适配器和列表视图 - c++ - 为什么我在输入 cout<<""< 时出现总线错误 10
我写了一个代码,但是有一个问题。当我
cout<<""<<endl;
熄灭时,我有 Bus error: 10. 我该如何解决这个问题。这是我的代码:#include <iostream> #include <sst
- sublimetext3 - Sublime 3 scroll_past_end 设置它将滚动过去的行数
- node.js - 使用 nodejs/typescript 应用程序中的 npm 库 @google-cloud/storage 从 GCP 存储桶下载文件非常慢
- expo - 无法在世博项目中实现通用链接
- google-sheets - 单元格引用不起作用,它们似乎是字符串而不是引用,如何解决?
- mysql - laravel 检索 old() 其中查询值
- .net - 将 Angular 12 的 FormData 中的对象传递给 .net core api
- jpa - 为什么持久化上下文称为持久化上下文?