ro_*_*nte 10 html css ruby-on-rails
我一直在尝试将一些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>
Run Code Online (Sandbox Code Playgroud)
输出这个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>
Run Code Online (Sandbox Code Playgroud)
相反,我想输出这个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>
Run Code Online (Sandbox Code Playgroud)
我试过以下,这不起作用......
<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>
Run Code Online (Sandbox Code Playgroud)
关于我怎么能这样做的任何想法?
小智 29
试试这样:
<%= 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 %>
Run Code Online (Sandbox Code Playgroud)
使用内联块要短一点
<%= f.collection_check_boxes(:brand_ids, Brand.all, :id, :name) do |b| %>
<%= b.label(class:"label-checkbox") { b.check_box + b.text } %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7539 次 |
| 最近记录: |