我希望将以下内容collection_select
按 分组State
,这是一个字段,Tuning
即Public
或Private
。这可能吗?
在视图中:
<%= collection_select :tunings, :tuning, @fretboard_tuning_options, :id, :name, {}, { :multiple => false, class: "", id: "tuning", style: 'width: 100%;' } %>
在控制器中:
@fretboard_tuning_options = Tuning.where('state=? OR user_id=?', 'Public', current_user.id)
任何具有公共状态的调整都不会与那些具有 user_id = current_user.id 的调整重叠。目标是有一个下拉框(我使用 Select2 来格式化下拉列表),显示两组选项:公共和私人,每组下是相关的调整。这可能吗?
谢谢!