simple_form中的分组集合

时间:2014-06-02 09:48:24

标签: ruby-on-rails ruby simple-form

我正在尝试在Ruby on Rails中创建分组集合。我用“select_tag”帮助器创建了一个。它看起来像这样: 在我的控制器中,我有变量,这是一个哈希:

 @cities = {
  'USA'      => ['Washington', 'New York'],
  'Bulgaria' => ['Sofia', 'Svishtov']
}

以我的形式:

 = select_tag :handover_location, grouped_options_for_select(@cities)

这会产生带有optgroups标签的mi nice选择。我怎么能用simple_form做同样的事?

1 个答案:

答案 0 :(得分:1)

对于simple_form,请尝试:

f.input :handover_location, collection: @cities, as: :grouped_select, group_method: :last, group_label_method: :first

(未经测试)