I would like to preselect multiple options when using grouped_options_for_select in rails 4.1
The method signature is
grouped_options_for_select(grouped_options, selected_key= = nil, options = {})
The selected_key only allows a single value which matches exact options. I would like to preselect multiple options since i am using a multi-select. Is there anyway to do this?
You can make
selected_keyan array of values for exactly your case.From the documentation:
If you look at the source for
grouped_options_for_selectit just callsoptions_for_selectpassingselected_key.