我正在使用simple_form gem来获取单选按钮,我收到了这段代码:
<% f.input :foo, collection: @bar, as: :radio_buttons %>
我也尝试过:
<% f.input :foo, collection: @bar, as: :radio_buttons, wrapper: :inline_form %>
和
<% f.input :foo, collection: @bar, as: :radio_buttons, :item_wrapper_class => 'inline' %>
html生成:
<div class="controls">
<label class="radio">
<input class="radio_buttons required" type="radio" value="true">
First Option
</label>
<label class="radio">
<input class="radio_buttons required" type="radio" value="false">
Second Option
</label>
</div>
html预期:
<div class=”controls”>
<span class=”radio”>
<input class=”radio_buttons required” type="radio" value="true">
<label class=”collection_radio_buttons”>First Option</label>
</span>
<span class=”radio”>
<input class=”radio_buttons required” type="radio" value="false">
<label class=”collection_radio_buttons”>Second Option</label>
</span>
</div>
我正在使用simple_form 3.5.0和rails 5。
Obs:我从this link获取了这些html行,但我尝试了作者的方法并没有改变。
他改变了 simple_form.rb :
config.boolean_style from:嵌套到:inline
并添加到同一个文件中:
config.wrappers :block_checkbox_and_radio, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper :tag => 'div', :class => 'controls' do |input|
input.use :input, :wrap_with => {:class => 'block-wrapper' }
input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
input.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
end
end