【问题标题】:Permit array in params参数中的允许数组
【发布时间】:2016-08-29 14:19:57
【问题描述】:

我有以下 JSON:

{
    "name": "pizza",
    "ingredients": [
        {"name": "tomato", "amount": 3, "unit": "un"},
        {"name": "chesse", "amount": 100, "unit": "gr"}
    ]
}

我使用 POST 将此 JSON 传递给我的控制器,然后我需要信任此参数,但我无法允许哈希数组 ingredients

如何允许? 我试过params.permit(:ingredients).permit(:name, :amount, :unit).to_h,但它不起作用。

【问题讨论】:

    标签: ruby-on-rails json


    【解决方案1】:

    params.permit(:name, :ingredients => [:name, :amount,:unit]) 应该可以解决问题。

    阅读Nested Parameters

    【讨论】:

      猜你喜欢
      • 2013-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-09
      相关资源
      最近更新 更多