添加自定义 class 到 simple_form_for 关联类型选项 - Rails

Add custom class to simple_form_for association of type option - Rails

我正在使用 simple_form_for 与关联

= f.association :type, :collection =>version_name,:label => "Application type:", :selected =>'', :item_wrapper_class => 'lbl_type'

这会生成如下所示的 html,

<div class="control-group select optional">
<label class="select optional control-label" for="subscription_type_id">Application type:</label>
<div class="controls">
<select class="select optional control-label" id="subscription_type_id" name="subscription[type_id]">
<option value="4">Type 1</option>
<option value="5">Type 2</option>
</select>
</div>
</div>

我试过 item_wrapper_class 但它不起作用

如何将特定自定义 类 添加到控件标签和输入字段

有什么办法可以实现吗?

试试下面的 input_html 属性。

= f.association :type, :collection =>version_name,:label => "Application type:", :selected =>'', input_html: { class: 'yourclass'}