For a recent Rails project I had the following setup:
In my view, I want to select 0-n users. Actually the first challenge was to create the checkboxes in a way the selected options get submitted as an array. It’s been ages since I last used checkboxes!
This way, the selected user IDs will get submitted as an array.
The next problem was Strong Parameters. Even though I added
permit(:user_ids), I got an Error message saying something aling “Parameter ‘user_ids’ not allowed.”.
Digging in the API from ActionController::Parameters I discovered that only some scalar types are allowed. To allow Arrays, they have to be declared as such:
If you’re new to Strong Parameters, I highly recommend reading Strong Parameters by Example by sensible.io.