The following before filter looks for any Hash
parameters where all the keys are integers and turns them into Array
s. It searches recursively to allow the used of nested attributes within nested attributes. This is necessary to circumvent a bug in the strong_parameters
gem which was reported in April 2012. Given params like:
{
"person" => {
"dogs_attributes" => {
"0" => {
"name" => "Fido"
},
"1" => {
"name" => "Rocket"
}
}
}
}
It will modify them to look like:
{
"person" => {
"dogs_attributes" => [
{
"name" => "Fido"
},
{
"name" => "Rocket"
}
]
}
}
Simply copy the before_filter
macro and repair_nested_params
method below into your application controller.
For rails 5