在check_box_tag中添加一个类

Rai*_*lsH 2 checkbox ruby-on-rails

我在网上搜索并找不到办法.到目前为止,我尝试过:

<%= check_box_tag "course[location_ids][]", location.id, class: 'checkbox-inline'%>
Run Code Online (Sandbox Code Playgroud)

这将输出:

input type: "checkbox" name="course[location_ids][] id="course_location_ids_" value="1" checked="checked"
Run Code Online (Sandbox Code Playgroud)

出于某种原因,它会进行检查输入.

<%= check_box_tag "course[location_ids][]", location.id, :class => 'checkbox-inline'%>
Run Code Online (Sandbox Code Playgroud)

和第一个一样

如何在check_box_tag中添加类

Dee*_*ale 10

您没有使用正确的格式

check_box_tag(name, value = "1", checked = false, options = {})
Run Code Online (Sandbox Code Playgroud)

将标记更改为以下内容:

<%= check_box_tag "course[location_ids][]", location.id, false, class: 'checkbox-inline'%>
Run Code Online (Sandbox Code Playgroud)

注意:第3个选项是选中的值,您需要根据需要进行更改

参考: check_box_tag