2017-08-09 59 views
0

在我的simple_form中,我有一個字段,其中包含作爲一系列複選框的集合。它很長,佔用了很多空間。Rails 5 - 使用item_wrapper_tag在simple_form中設置集合

我想使用CSS設置複選框的樣式,以便將其限制在180像素高度幷包含在可滾動框中。我在simple_form代碼:

<th>Authors</th> 
    <td><%= f.association :authors, as: :check_boxes, item_wrapper_tag: :div, item_label_class: 'h_180', label: false, collection: Author.order('name ASC') %></td> 

我包裹在一個div軌輸出與item_wrapper_tag: :div。我如何設計這個div? item_label_classitem_wrapper_class都不起作用。有

回答

0

我在我的應用程序複選框的選擇,但我實現它有所不同:

<%= f.collection_check_boxes(:item_ids, Item.all.sort_by { |x| x.name }, :id, :name) do |b| %> 
    <%= b.label class: "label-checkbox", style:"padding-right:5px" do > 
      <%= b.check_box + " " + b.text + " "%> 
    <% end %> 
<% end %> 

我想你可以再次風格的複選框的標籤樣式的方式:

<%= (b.check_box class: "checkbox-class", style: "checkbox-style") + " " + b.text + " "%> 

如果您選擇以這種方式實施選擇,請確保允許控制器接收:item_ids作爲參數。