rails/rails — pull request #9620 by lawrencepit (2013-03-09 04:16:51+00:00)
Title: Priority options for form.select, options_for_select and options_from_collection_for_select

We have several select boxes with relatively long lists and want a small set of options to be placed at the top as they are used most often. And/or where we want to emphasise a certain option by always placing it at the top. Think of lists showing time zones, countries, languages, etc.

Currently `time_zone_select` does something similar. This patch generalizes that case.

It accepts a `priority` option for form.select, options_for_select and options_from_collection_for_select. When specified the given values will be placed at the top of select options, followed by all the options separated by a line.

For example, the country_select plugin/gem then becomes a simple one-liner:
```
f.select :country, COUNTRIES, :priority => ["United States", "Canada"]
```

The method `time_zone_options_for_select` delegates to `options_from_collection_for_select`. The time zone method would not show the priority zones below the fold. This patch will show the priorities at top, but also in their usual place below the fold. Especially in long lists users get confused when they are for example looking for the country "United States" at the bottom of the list, but then can't find it because it's shown as a priority country at the top. If a priority option is selected the option below the fold is not selected.