2015-11-07 46 views
0

我有這樣的協會。寫在軌道地圖與f.select?

company has many city_groups 
and city_groups has many cities 

我如何使用map方法使f.select在drop_down中顯示城市名稱。並在內部我想保存城市ID。

<%= builder.collection_select :city, @company.city_groups.map{ |city_groups|.each do |city| {city.id city.name} } || [], :id ,:name, {:include_blank=>'<option disabled=true selected=selected >Please Select</option>'.html_safe}, {:class=>"form-control", :id=>"" } %> 

回答

0

下面的代碼應該工作

<%= builder.collection_select :city, @company.city_groups.map{ |city| [ city.id, city.name ] }, {:include_blank: true } %>