I need to add a custom HTML attribute to each option for a select control. I\'m using simple_form in Rails. Does anyone know how to do this? The at
You're close! easiest way is actually not using simple_form here. here's the simple_form documentation
<% options = @group.map { |g| [g.name, g.id, {'data-type' => g.group_type}] } %>
<%= f.input :group, label: 'Group' do %>
<%= f.select :group, options, include_blank: 'Select a Group', class: 'form-control' %>
<% end %>
For your exact code it would be:
<% options = @group.map { |g| [g[0], g[1], {'data-type' => g[2]}] } %>
<%= f.input :group, label: 'Group' do %>
<%= f.select :group, options, include_blank: 'Select a Group', class: 'form-control' %>
<% end %>