I have a simple block eachthat accepts each category and createsoption
@categories = Category.all
<select id="bike_category_filter" multiple="multiple">
<% @categories.each do |c| %>
<option value="<%= c.name %>"><%= c.name %></option>
<% end %>
What I would like with categories Men and Women(so c.name) to surround them with a tag <optgroup>. How could I achieve this, a link to a resource or an explanation of where to look would be enough, it’s not necessary to search for someone to give me an answer
The desired result will look like
<select>
<optgroup label="Gender">
<option value="cat1">Men</option>
<option value="cat2">Women</option>
</optgroup>
<option value="cat3">Cat5</option>
<option value="cat4">Cat4</option>
</select>
thank
source
share