I’m proposing an enhancement per the contribution guidelines, and looking to find out whether this patch might be accepted.
HTML5 added the “multiple” attribute to fields. This is useful as it means the user agent can perform email validation and strip whitespace.
However, the actual emails are submitted to the server as a comma-separated string.
Additionally, Rails magic turns something like
<%= f.email_field :emails, multiple: true %>
When submitted, we actually receive this:
params[:emails] = “foo,bar”
But we actually want this:
params[:emails] = [“foo”, “bar”]
I’m proposing a patch to handle some or all of this unusual (but standards based) behaviour.
When rendering an :email_field with the multiple property:
- When the ActiveModel attribute is an Array, the value should be joined into a string separated by commas.
- Alternatively, the value should be absent, and a should be added to the output
- Don’t append  to the name, so the form value remains a string rather than an array of strings
- Append a hidden form input to indicate the Rails should interpret that form value as a comma-separated string, and turn it into an array