ToddT
ToddT

Reputation: 3258

Nested Strong Params with arrays and hashes

I can almost get everything I need from these params (which I've simplified)

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"
    } 
  }

This is what I have so far:

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

What I'm missing is the currency value. I've tried the following with no luck:

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])

And many more similar iterations. Some reason I can't get that currency value. Any help??

Upvotes: 0

Views: 100

Answers (1)

Pavan
Pavan

Reputation: 33542

The below should work

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

Upvotes: 1

Related Questions