how to permit the parameters for bulk creation with has_many association records in rails

307 Views Asked by At
{
    "people": [
        {
            "last_name": "batch_person_one",
            "addresses":[{
                "address_type": "active"
            }],
            "bank_accounts": [{
                "account_type": "saving"
            }]
        },
        {
            "last_name": "second one",
            "addresses": [],
            "bank_accounts": [],
        }
    ]
}

Above is the sample data which is coming to my application in API post request. So basically I need to add a strong parameter for above keys how can it be done.

1

There are 1 best solutions below

0
mechnicov On

You need something like this

params.permit(
  people: [
    :last_name,
    addresses: [[:address_type]],
    bank_accounts: [[:account_type]],
  ]
)