1

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!

1 Answer 1

1

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 
Sign up to request clarification or add additional context in comments.

3 Comments

not sure if this would work, as :array_param is nested inside :name
this worked permitted[:name][:array_param] = params[:name].require(:array_param)
Thank you, worked great! In the if statement I did check for params[:name][:array_param].present?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.