0

I have seen a lot of samples of Rails code, and I saw two versions of nested attributes in strong params:

params.require(:smth).permit(:a, b: [])
params.require(:smth).permit(:a, { b: [] })

Why do I need to use braces in the second example? Thanks in advance.

1
  • Those 2 examples are identical - the braces around a hash are optional when it is the last argument to a method Commented Sep 11, 2014 at 10:55

1 Answer 1

1

When you have several hash in permit params you should separate by braces:

params.require(:smth).permit(:a, { b: [] }, { c: [] })

this should raise syntax error:

params.require(:smth).permit(:a,  b: [] , c: [] )
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! It's pretty simple :)

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.