我希望通过State对以下collection_select进行分组,这是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格式化下拉框),它显示两组选项:公共和私有,每组下都有相关的调整。这个是可能的吗?
谢谢!
发布于 2014-03-21 11:39:21
你想要grouped_collection_select:http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-grouped_collection_select
https://stackoverflow.com/questions/22549605
复制相似问题