在 Rails 中发送带有区分大小写键的请求数据

Sending request data with case sensitive keys in Rails

作为表单的一部分,我在将请求中的 JSON 对象发送到 Rails 后端。请求数据如下所示:

{"choiceNames": {
  "Key Name A": true,
  "Key Name B": true
}}

这个例子是人为设计的,但重点是键名区分大小写。在 Rails 控制器中,当使用 params 查看数据时,所有的键都被小写了。

{"choiceNames" => {
  "key name a" => true,
  "key name b" => true
}}

如何防止 Rails 进行这种小写操作?

你必须阅读,6.2.2.1. The RFC for URIs: Case Normalization 其中指出,

When a URI uses components of the generic syntax, the component syntax equivalence rules always apply; namely, that the scheme and host are case-insensitive and therefore should be normalized to lowercase.

在controller中获取大写形式。