如何使用ruby添加粗体标题(又名optgroup)
和select2
?
<%= @challenge.select(:name, [[], ['optgroup label: Mind'], ['Write a Book'], ['Paint a Picture'], ['optgroup label: Body'], ['Run a 5K'], ['Lose 10 Pounds']]) %>
$('select').select2({
placeholder: "Enter Challenge",
theme: "bootstrap",
allowClear: false,
tags: true,
multiple: false,
});
我很难将这里提供的答案翻译成红宝石解决方案:Select2 - How to insert a bolded headline?
答案 0 :(得分:1)
您是否尝试过:grouped_collection_select
?
http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/grouped_collection_select
更新了示例:
控制器:
@collection = [['Mind', ['Write a Book', 'Paint a Picture']], ['Body', ['Run a 5K', 'Lose 10 Pounds']]]
查看:
<%= @challenge.grouped_collection_select(:name, @collection, :last, :first, :to_s, :to_s, include_blank: true) %>
显然我没有确切的源代码,但这应该可行。