I have the following params, that have different value type (1. string, 2. array of strings and 3. array of hashes) for the value key:
Params
project: {
name: "Project 1",
field_values_attributes: [
{
field_component_id: 1,
value: "my_value"
},
{
field_component_id: 2,
value: ["my_value1", "my_value2"]
},
{
field_component_id: 3,
value: [
{
id: X,
attributes: {
uid: "my_uid",
email: "my_email",
full_name: "my_name"
}
}
]
}
]
}
Strong params:
def project_params
params.require(:project).permit(:name, field_values_attributes: [ :field_component_id, :value, value: [ :id, attributes: [:uid, :email, :full_name]] ])
end
The strong params method permits the string and array of hashes, but not array of strings for the value key.
Any idea how to write the permit method to accept all three types? Thanks.
You can add
value: []for achieving this.