在Rails haml模板中向collection_select添加一个类

时间:2015-02-07 02:09:31

标签: ruby-on-rails haml

我们在haml模板中有以下内容,并且正在尝试将类应用于下拉字段,但似乎无法弄明白。

 = f.collection_select(:thing_id, Thing.all, :id, :name, include_blank: true)

非常感谢任何帮助

2 个答案:

答案 0 :(得分:1)

这将有效 - >

= f.collection_select(:thing_id, Thing.all, :id, :name, include_blank: true, class: 'your_class_name')

答案 1 :(得分:0)

上述答案在rails 4.2.0中无效。但这样做了:

= f.collection_select(:thing_id, Thing.all, :id, :name, {include_blank: true}, {class: 'your_class_name'})

选项和html_options应该是哈希。

http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select