Ruby on rails 如何为RubyonRails集合添加引导的表单控制类

Ruby on rails 如何为RubyonRails集合添加引导的表单控制类,ruby-on-rails,ruby,bootstrap-4,Ruby On Rails,Ruby,Bootstrap 4,我有一个collection_select标记,用户可以在其中选择要为票证分配的web用户。所选集合上的项目将来自数据库 如何将引导的表单控件类添加到此集合\u select标记 我尝试了以下代码: <%= f.collection_select :web_user_id, WebUser.all,:id,:email, include_blank: true, class: 'form-control' %> 但它不起作用。我也读过这些,但没用 将代码转换为: <%= f.

我有一个collection_select标记,用户可以在其中选择要为票证分配的web用户。所选集合上的项目将来自数据库

如何将引导的表单控件类添加到此集合\u select标记

我尝试了以下代码:

<%= f.collection_select :web_user_id, WebUser.all,:id,:email, include_blank: true, class: 'form-control' %>
但它不起作用。我也读过这些,但没用

将代码转换为:

<%= f.collection_select :web_user_id, WebUser.all,:id,:email, {}, { :include_blank => true, class: 'form-control' } %>
它是该方法的html_选项的一部分。有关更多信息,请参阅

首先需要设置选项={},至少设置为空大括号{}

然后,您可以在第二个大括号之间设置include_blank和class html_options={}

最后的表单应该类似于include{},{:include_blank=>true,类:'form control'}

试试这个,它可能会对你有所帮助。

只需在下面添加{}:类似电子邮件的

并查看生成的HTML

<select include_blank="true" class="form-control" name="web_user[web_user_id]" id="web_user_web_user_id">
    <option value="20">avcd@example.com</option>
    <option value="21">sa@example.com</option>
</select>

您是否在web检查器中检查表单控件类是否存在于字段中?此外,您的界面或主题是否使用Boostrap,因为表单控件是其一部分?是的,它不存在于字段中。在这里,检查发生了什么:尝试使用我的答案的新编辑版本。在“{:include\u blank…”之前缺少{},您是使用表单还是简单表单?
<%= f.collection_select :web_user_id, WebUser.all, :id, :email, {}, include_blank: true, class: 'form-control' %>
<select include_blank="true" class="form-control" name="web_user[web_user_id]" id="web_user_web_user_id">
    <option value="20">avcd@example.com</option>
    <option value="21">sa@example.com</option>
</select>