用铁轨中的地图写f.select?

时间:2015-11-07 05:18:32

标签: ruby-on-rails select dictionary has-many

我正在接受这样的协会。

string tail_repeater(string left, string right){
    if (right == ""){
       return left;
    }
    return tail_repeater(left + right.substr(0,1) + right.substr(0,1), right.substr(1));
}

string repeater(string str){
   tail_repeater("", str);
}

我如何使用map方法获得f.select,以便在drop_down中我可以显示城市名称。在内部我想保存城市ID。

company has many city_groups 
and city_groups has many cities

1 个答案:

答案 0 :(得分:0)

以下代码应该有效

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