2014-03-04 37 views
0

如何将这个select显示为分组集合select。我尝试了各种不同的类型,并没有奏效。任何帮助表示赞赏。Rails 3.2上的grouped_collection_select

enter image description here

<%= f.select :agency_type_id, AgencyType.joins(:sector).order('sectors.name ASC, name ASC').map {|atype| ["#{atype.sector.name} - #{atype.name}", atype.id]}, :prompt => "Select Sector - Agency Type" %> 

我想通过分组部门,然后公司类型显现。
例如:
大弯
     联邦执法机关
     当地执法机关
德里奥
     联邦执法机关
     本地LEA
等等...

+0

在这里检查http://stackoverflow.com/a/1192862/687142 – xlembouras

回答

0

经过摆弄API后,我得到了解决方案:

<%= f.grouped_collection_select :agency_type_id, Sector.order('name ASC'), :agency_types, :name, :id, :name, :prompt => "Select Agency Type" %>