This blog is part of our Rails 5 series.
Consider the following form which has only one input
role_id which is accepted through
In the controller, we can access
role_id using the strong parameters.
When we try to submit this form without selecting any radio button in Rails 4.x,
we will get
400 Bad Request error with following message.
This is because following parameters were sent to server in Rails 4.x .
According to HTML specification, when multiple parameters are passed to
collection_radio_buttons and no option is selected, web browsers do not send any value to the server.
Solution in Rails 5
adds hidden field on the collection_radio_buttons
to avoid raising an error when the only input on the form is
The hidden field has the same name as collection radio button and has blank value.
Following parameters will be sent to server in Rails 5 when above user form is submitted:
In case we don’t want the helper to generate this hidden field, we can specify