Html 设置Rails集合的样式\u复选框
我一直在尝试将一些CSS类应用于集合复选框,但我无法使其工作。现在我正在做这件事:Html 设置Rails集合的样式\u复选框,html,css,ruby-on-rails,Html,Css,Ruby On Rails,我一直在尝试将一些CSS类应用于集合复选框,但我无法使其工作。现在我正在做这件事: <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> 哪个输
<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>
<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>
品牌1
相反,我希望输出以下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>
<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>
品牌1
我尝试了以下方法,但不起作用
<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>
有什么办法可以这样做吗?像这样试试:
<%= f.collection_check_boxes(:brand_ids, Brand.all, :id, :name) do |b| %>
<%= b.label class:"label-checkbox" do%>
<%=b.check_box + b.text%>
<%end%>
<% end %>
使用内联块稍微短一点
<%= f.collection_check_boxes(:brand_ids, Brand.all, :id, :name) do |b| %>
<%= b.label(class:"label-checkbox") { b.check_box + b.text } %>
<% end %>
我拆分了,以便添加跨度标签。但通过第二个街区是关键。