在Rails 5中将类添加到bootstrap_form_for collection_select

时间:2017-01-12 15:59:11

标签: ruby-on-rails form-for

我使用bootstrap_form_for创建表单并有一个集合选择,我想添加一个自定义类。我尝试过这个,但这不起作用:

<%= f.collection_select :location, Location.all, :id, :name, label: 'Location', :include_blank => ("Select..."), hide_label: true, :class => 'location' %>

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

许多Rails助手使用多个哈希参数。

这个collection_select方法的定义如下:

collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})

因此您的选择字段将是:

<%= f.collection_select :location, Location.all, :id, :name,
    {label: 'Location', :include_blank => ("Select..."), hide_label: true}, {class: "location"} %>