2013-03-11 93 views
0

好吧,這是一個非常簡單的問題,但對於我的生活,我無法在任何地方找到它。我發現了一些非常接近我需要的東西,但沒有具體的東西。與td標籤環繞simple_form關聯

因此,這裏是我的看法:

<tbody> 
    <% permissions.each do |permission| %> 
    <tr> 
     <td><%= permission.label %></td> 
     <%= simple_form_for permission do |f| %> 
     <%= f.association :roles, as: :check_boxes, label: false, label_method: lambda { |p| "" }, fields_element: "<td>" %> 
     <% end %> 
    </tr> 
    <% end %> 
    <%= debug(permissions) %>  
    </tbody> 

我只是希望把每個角色在自己的TD標記。我有一種感覺,答案非常簡單,以至於沒有人會對此發表任何評論。請幫忙!

+0

有人boolean_style: :inline發佈的答案是說我應該使用wrapper_tag。但是,我已經嘗試過這一點,它將td標籤放在所有相關角色的周圍,而不是每個角色。當我提到這個問題時,答案被刪除了,但我想在這裏發表評論,所以我沒有得到相同的答案。謝謝! – 2013-03-11 15:17:20

回答

1
= f.association :roles, as: :check_boxes, item_wrapper_tag: :td 

如果您正在使用的自舉,將此選項添加到輸入:根據https://github.com/plataformatec/simple_form/issues/685#issuecomment-10184181

+0

這可行,但會導致一個小問題。我正在使用label_method:lambda {| p | 「」}刪除標籤,但現在標籤返回爲「角色ids 1 /角色id 2等等」我的新輸入如下所示:<%= f.association:roles,如::check_boxes,label:false,label_method: lambda {| p | 「」},item_wrapper_tag :: td,boolean_style :: inline%> – 2013-03-11 15:29:23

+0

看來'label_method' /'item_wrapper_tag'和'boolean_style :: inline'是不兼容的。 'boolean_style :: nested'將隱藏標籤,但忽略:td標籤。 – Leito 2013-03-11 15:35:47

+0

我同意萊託。但是,這隻意味着我仍然沒有答案。它在這一點上是一個捕捉22。我要麼獲得標籤,要麼沒有td標籤。 – 2013-03-11 15:42:28