首页 > simple_form 中 grouped_collection_select 去掉空组

simple_form 中 grouped_collection_select 去掉空组

simple_form 的问题,希望用过的同学给支个招。

<%= f.grouped_collection_select :cat_id_equals, @categories, :subcat, :to_s, :id, :to_s, include_blank: '全部' %>

对于 grouped_collection_select 这个组件,如果分组中没有子项目,有什么办法将那个分组隐藏?


这个东西不是simple_form的东西,是Rails自己的一个View Helper,具体文档看这里: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-grouped_collection_select

@categories 提前把不需要的category剔除出去即可。

【热门文章】
【热门文章】