2

I'm having issues with Rails 4 Strong Parameters. The thing is I try to pass some parameters that look like this and it raises a ForbiddenAttributesError exception afterwards:

"survey_answer"=>{"a1"=>"answer_1",
 "a2"=>"answer_1",
 "a3"=>"answer_3",
 "a4"=>["test1",
 "test2",
 "test3"],
 "a7"=>"answer_7",
 "name"=>"Test name",
 "industry"=>"Test industry",
 "email"=>"[email protected]"}}

As you can see, a4 comes from a check box that yields an array of values. My proposed solution to this point is this:

params.require(:survey_answer).permit(:a1, :a2, :a3, :a7, :name, :email, :industry, :a4 => [], :a5, :a6)

Unfortunately no matter how I refactor I still get to the same point.

1

2 Answers 2

0

Try this.

params.require(:survey_answer).permit(:a1, :a2, :a3, :a7, :name, :email, :industry, {:a4 => []}, :a5, :a6)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I still get forbidden access though.
0

try this it worked for me

params.require(:survey_answer).permit(:a1, :a2, :a3, :a7, :name, :email, :industry, :a5, :a6, a4: [])

just shift your array type argument at the end. I hope this will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.