带有数组和哈希值的嵌套强参数

时间:2018-09-24 22:57:17

标签: ruby-on-rails ruby parameters

我几乎可以从这些参数中获得所需的一切(我已经简化了)

h = { "rate"=>{
        "destination"=>{
        "country"=>"US", "postal_code"=>"12345", "province"=>"NC",
        "city"=>"Charlotte", "name"=>"mine", "address1"=>"12 Main"
      },
      "items"=>[
        {
          "name"=>"Buy This", "sku"=>"MC-J4", "quantity"=>1,
          "fulfillment_service"=>"web", "properties"=>nil,
          "variant_id"=>13992832794667
        }
      ],
      "currency"=>"USD",
      "locale"=>"en"
    } 
  }

这是我到目前为止所拥有的:

params.permit(:domain, :type, rate: [destination: {}, items: [:name, :sku, :quantity, :fulfillment_service]])

我缺少的是currency值。我已经尝试过以下方法,但是没有运气:

params.permit(:domain, :type, rate: [destination: {:currency}, items: [:name, :sku, :quantity, :fulfillment_service]])

params.permit(:domain, :type, rate: [destination: {}, items: [:name, :sku, :quantity, :fulfillment_service], :currency])

还有更多类似的迭代。由于某些原因,我无法获得该currency值。有帮助吗?

1 个答案:

答案 0 :(得分:1)

下面应该可以工作

params.permit(:domain, :type, rate: [:currency, destination: {}, items: [:name, :sku, :quantity, :fulfillment_service]])