从 collection_check_boxes 移除外部标签

Remove outer label from collection_check_boxes

我正在从我的关联复选框中生成 table。每行显示一个复选框和一些附加信息。

%table
= f.collection_check_boxes :task_ids, @my_collection, :id, :label do |r|
  %tr
    %td= r.label
    %td= r.check_box
    %td= r.object.due_date

但这打破了我的 HTML 因为输出看起来像这样:

<table>
<span><label for="task_ids_1"> <--- I want to remove this...
  <tr>
    <td><label for="task_ids_1">My Name</label></td>
    <td><input type="checkbox" value="8" name="user[task_ids][]" id="task_ids_1" /></td>
    <td>I'm in.</td>
  </tr>
</label></span> <--- ...and this!
</table>

当然我试过设置label: false,但是这个选项没有效果。我怎样才能去掉外面的标签?

差不多一年后我终于自己弄明白了。有一个名为 boolean_style: :inline 的选项可以使它起作用。

%table
  = f.collection_check_boxes :task_ids, @coll, :id, :label, boolean_style: :inline do |r|
    %tr
      %td= r.label
      %td= r.check_box
      %td= r.object.due_date

我在这里找到了解决方案和解释 https://github.com/plataformatec/simple_form/issues/1266:

Since you want it to be inline (because you're making it nested by yourself) you need to use boolean_style: :inline config.