ruby on rails f.select options with custom attributes
Rails CAN add custom attributes to select options, using the existing options_for_select helper. You almost had it right in the code in your question. Using html5 data-attributes: <%= f.select :country_id, options_for_select( @countries.map{ |c| [c.name, c.id, {‘data-currency_code’=>c.currency_code}] }) %> Adding an initial selection: <%= f.select :country_id, options_for_select( @countries.map{ |c| [c.name, c.id, {‘data-currency_code’=>c.currency_code}] }, selected_key = f.object.country_id) … Read more