问题
I am generating a table from my association checkboxes. Each row shows a checkbox and some additional information.
%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
But this breaks my HTML since the output looks like this:
<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>
Of course I tried to set label: false
, but this option has no effect. How can I get rid of the outer label?
回答1:
I finally figured it out by myself almost one year later. There is an option called boolean_style: :inline
that makes it work.
%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
I found the solution and explanation here 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.
来源:https://stackoverflow.com/questions/37975486/remove-outer-label-from-collection-check-boxes