Style Rails collection_check_boxes [英] Style Rails collection_check_boxes
本文介绍了Style Rails collection_check_boxes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在试图应用一些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_1name =user [brand_ids] []type =checkboxvalue =1> Brand 1
< / label&
< input name =user [brand_ids] []type =hiddenvalue =>
< / div> < div class =form-group>
< label class =label-checkboxfor =user_brand_ids_1>
< input id =user_brand_ids_1name =user [brand_ids] []type =checkboxvalue =1>
< span class =custom-checkbox>< / span> Brand 1
< / label>
< input name =user [brand_ids] []type =hiddenvalue =>
< / 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>任何想法如何可以这样做?
$ b < h2_lin>解决方案
尝试如下:
<%= f.collection_check_boxes :brand_ids,Brand.all,:id,:name)do | b | %>
<%= b.label class:label-checkboxdo%>
<%= b.check_box + b.text%>
<%end%>
<%end%>
I been trying to apply some CSS classes to collection_check_boxes but I can't get it to work. Right now I doing this:
<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>
which outputs this 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>
Instead I would like to output this 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>
I've tried the following, which doesn't work...
<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>
Any ideas on how could I do this?
解决方案
Try it like this:
<%= 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 %>
这篇关于Style Rails collection_check_boxes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文