出于某种原因,SimpleForm 对待日期字段的方式与其他字段不同。这是运行安装后的标准输出。您可以看到 DOB (Date) 缺少一些我需要添加的元素:
- 添加 col-sm-3 类
class=" col-sm-3控制标签
- 添加一个 col-sm-9 div
< div class="col-sm-9" >
宝石文件
gem 'bootstrap-sass'
gem 'bootstrap-sass-extras'
gem 'simple_form'
_form.html.erb
<%= simple_form_for @firm_info, html: { class: 'form-horizontal' }, wrapper: :horizontal_form, wrapper_mappings: { check_boxes: :horizontal_radio_and_checkboxes, radio_buttons: :horizontal_radio_and_checkboxes, file: :horizontal_file_input, boolean: :horizontal_boolean } do |f| %>
<%= f.input :last_name %>
<%= f.input :dob %>
_form.html(结果)
<div class="form-group string optional firm_info_last_name">
<label class="col-sm-3 control-label string optional" for="firm_info_last_name">Last name</label>
<div class="col-sm-9">
<input class="form-control string optional" name="firm_info[last_name]" id="firm_info_last_name" type="text">
</div>
</div>
<div class="form-group date optional firm_info_dob">
<label class="control-label date optional" for="firm_info_dob_1i">Dob</label>
<div class="form-inline">
<select id="firm_info_dob_1i" name="firm_info[dob(1i)]" class="form-control date optional">
<option value="2011">2011</option>
<option value="2012">2012</option>
</select>
<select id="firm_info_dob_2i" name="firm_info[dob(2i)]" class="form-control date optional">
<option value="1">January</option>
<option value="2">February</option>
</select>
<select id="firm_info_dob_3i" name="firm_info[dob(3i)]" class="form-control date optional">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="3">3</option>
</select>
</div>
</div>
_form.html(我希望它看起来像什么)
<div class="form-group string optional firm_info_last_name">
<label class="col-sm-3 control-label string optional" for="firm_info_last_name">Last name</label>
<div class="col-sm-9">
<input class="form-control string optional" name="firm_info[last_name]" id="firm_info_last_name" type="text">
</div>
</div>
<div class="form-group date optional firm_info_dob">
<label for="firm_info_dob_1i" class="**col-sm-3** control-label date optional">Dob</label>
**<div class="col-sm-9">**
<div class="form-inline"><select id="firm_info_dob_1i" name="firm_info[dob(1i)]" class="form-control date optional">
<option value="2011">2011</option>
<option value="2012">2012</option>
</select>
<select id="firm_info_dob_2i" name="firm_info[dob(2i)]" class="form-control date optional">
<option value="1">January</option>
<option value="2">February</option>
</select>
<select id="firm_info_dob_3i" name="firm_info[dob(3i)]" class="form-control date optional">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="3">3</option>
</select>
</div>
</div>