collection_select on controller update actions

When doing a controller update operation, missing parameters are treated as unchanged. This is a great convention but I'm not sure how to handle this when using a collection_select.

If a user deselects all items in a the HTML select, nothing is sent on the update action.

For example, if 2 items are selected I get params[:selected_location_ids] == ["22", "242"]

if no items are selected the params[:selected_location_ids] is not sent.

Is there a way to make the HTML form send an empty option when nothing is selected so I can know if the user deselected everything vs an alternate form not sending this information?

Try passing a hidden_field_tag with the location_ids set to blank underneath the collection_select.

ex:

<%= hidden_field_tag '[selected_location_ids]' %>