简体   繁体   English

如何允许带有 Rails 的阵列 json?

[英]How to permit an array json with Rails?

For json适用于 json

{
   "version":"1",
   "configs":[
      {
         "title":"Good",
         "body":"Body"
      },
      {
         "title":"Good",
         "body":"Body"
      }
   ]
}

How to permit it with Rails' params.permit in controller?如何在 controller 中使用 Rails 的params.permit来允许它?

I tried我试过了

  params.permit(
    config_setting: [
      :version,
      configs: [
        :title,
        :body,
      ]
    ],
  )

But seems not right.但是好像不对。

Currently you are permitting a json with the following structure:目前,您允许 json 具有以下结构:

{
   "config_setting": [
      {
         "version":"1",
         "configs":[
            {
               "title":"Good",
               "body":"Body"
            },
            {
               "title":"Good",
               "body":"Body"
            }
         ]
      }
   ]
}

Just add config_setting node to the data or adjust your strong params block to:只需将config_setting节点添加到数据或将您的强参数块调整为:

params.permit(
   :version,
   configs: [
     :title,
     :body,
   ] 
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM