【发布时间】:2014-07-16 00:51:15
【问题描述】:
我一直在尝试将一些 CSS 类应用于 collection_check_boxes,但我无法让它工作。现在我正在这样做:
<div class="form-group">
<%= f.collection_check_boxes(:brand_ids, Brand.all, :id, :name) do |b| %>
<%= b.label { b.check_box + b.text } %>
<% end %>
</div>
输出此 HTML:
<div class="form-group">
<label for="user_brand_ids_1">
<input id="user_brand_ids_1" name="user[brand_ids][]" type="checkbox" value="1">Brand 1
</label>
<input name="user[brand_ids][]" type="hidden" value="">
</div>
相反,我想输出这个 HTML:
<div class="form-group">
<label class="label-checkbox" for="user_brand_ids_1">
<input id="user_brand_ids_1" name="user[brand_ids][]" type="checkbox" value="1">
<span class="custom-checkbox"></span>Brand 1
</label>
<input name="user[brand_ids][]" type="hidden" value="">
</div>
我尝试了以下方法,但不起作用...
<div class="form-group">
<%= f.collection_check_boxes(:brand_ids, Brand.all, :id, :name, {}, {class: 'label-checkbox'}) do |b| %>
<%= b.label { b.check_box + b.text }, class: 'label-checkbox' %>
<% end %>
</div>
关于如何做到这一点的任何想法?
【问题讨论】:
标签: html css ruby-on-rails