2016-06-22 58 views
3

我從我的關聯複選框中生成一個表。每行顯示一個複選框和一些附加信息。從collection_check_boxes中刪除外部標籤

%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,但該選項沒有任何影響。我如何擺脫外部標籤?

回答

1

我終於在一年後終於明白了。有一個選項叫做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

既然你希望它是內聯(因爲你讓通過 嵌套自己),你需要使用boolean_style:直列配置。