删除 ruby 中复选框的外部标签
remove outer label of checkbox in ruby
我在我的项目中使用 ruby。我需要复选框的自定义样式。
请查找以下代码
<%= f.input :category_ids, :as => :check_boxes do %>
<%= f.collection_check_boxes :category_ids, Category.order(:name), :id, :name do |b|
b.label { b.check_box + b.text }
end %>
<% end %>
使用上面的代码我就像
<label for="property_space_amenities_space_amenities_2">
<input type="checkbox" value="2" name="property[space_amenities][space_amenities][]" id="property_space_amenities_space_amenities_2">Internet connectivity
</label>
我无法为此提供自定义样式
我想要如下输出
<label class="control-label" for="user_login">Login</label>
<input class="form-control" id="user_login" name="user[login]" type="text" />
请帮帮我
根据 rails doc,您可以通过不使用 "do" 块来分离标签和复选框。
<%= f.collection_check_boxes :category_ids, Category.order(:name), :id, :name %>
顺便说一句,这仅适用于 rails >= 4.0.2,也许您可以删除 rails 3 标签。
我在我的项目中使用 ruby。我需要复选框的自定义样式。
请查找以下代码
<%= f.input :category_ids, :as => :check_boxes do %>
<%= f.collection_check_boxes :category_ids, Category.order(:name), :id, :name do |b|
b.label { b.check_box + b.text }
end %>
<% end %>
使用上面的代码我就像
<label for="property_space_amenities_space_amenities_2">
<input type="checkbox" value="2" name="property[space_amenities][space_amenities][]" id="property_space_amenities_space_amenities_2">Internet connectivity
</label>
我无法为此提供自定义样式
我想要如下输出
<label class="control-label" for="user_login">Login</label>
<input class="form-control" id="user_login" name="user[login]" type="text" />
请帮帮我
根据 rails doc,您可以通过不使用 "do" 块来分离标签和复选框。
<%= f.collection_check_boxes :category_ids, Category.order(:name), :id, :name %>
顺便说一句,这仅适用于 rails >= 4.0.2,也许您可以删除 rails 3 标签。