Reputation: 215
I am trying to accept a multi-dimensional array using strong_params.
I was using:
params.require(:name).permit(array_param: [])
and it was working fine for regular arrays.
Now I got a multi-dimensional array format I have to deal with. The previous solution is not working for the following case.
[[1],[2],[2,1]]
I would gladly appreciate some guidance. Thanks!
Upvotes: 1
Views: 84
Reputation: 20033
You need to take the long route and do it like this
def permitted_params
permitted = params.require(:name)
if params[:name][:array_param].present?
permitted[:name][:array_param] = params[:name].require(:array_param)
end
permitted
end
Upvotes: 1