1

我希望将以下内容collection_select按 分组State,这是一个字段,TuningPublicPrivate。这可能吗?

在视图中:

<%= 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 来格式化下拉列表),显示两组选项:公共和私人,每组下是相关的调整。这可能吗?

谢谢!

4

1 回答 1

2

你想要grouped_collection_selecthttp ://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-grouped_collection_select

于 2014-03-21T03:39:20.537 回答