The Rails documentation doesn't seem to mention this, but it's possible to add your own custom HTML attributes to the option tags generated using options_for_select
In our case, we wanted to add custom HTML5 data attributes to our options tags we could use unobtrusive javascript to notice when the the user made a new selection and update another part of the page with the contents of the selected option tag's data attribute
I found someone else actually recommend doing a copy/paste/rewrite of options_for_select
, but if you dig into the Rails code a bit you'll find this is totally unnecessary. This is from form_options_helper.rb
- the two methods that get called on each element of the array you pass to