simple_form日期输入未显示在同一行中

时间:2015-02-27 23:34:08

标签: ruby-on-rails twitter-bootstrap ruby-on-rails-4 simple-form

我的表单中有输入日期:

<%= simple_form_for @user, url:wizard_path, html: {class: 'form-horizontal'}, wrapper: :horizontal_input_group do |f| %>
    <%= f.simple_fields_for :educations do |b| %>
    <%= b.input :school_name %>
    <%= b.input :degree %>
    <%= b.input :year_started %>
    <%= b.input :year_finished %>
    <% end %>
    <%= f.button :submit, "Continue" %>
    or<%= link_to " Skip this step", next_wizard_path%>
    <% end %>

我的问题是,月份和年份输入不在同一行,看起来很丑(即它显示3行,每行一个输入)。我认为simple_form的默认行为会在同一行显示日期输入,但我的不是。这在simple_form中是正常的吗? (具体是日期输入)还是我需要通过css进行一些配置?请帮帮我:(

相关型号:

用户模型:

has_many :educations, dependent: :destroy
accepts_nested_attributes_for :educations

教育模式:

belongs_to :user

1 个答案:

答案 0 :(得分:0)

环顾四周后,我找到了问题的答案here

我希望在不使用css的情况下解决这个问题,因为我认为simple_form有办法处理这类事情。

HTML:

<select id="user_educations_attributes_0_year_started_3i" name="user[educations_attributes][0][year_started(3i)]" class="date required form-control">

<select id="user_educations_attributes_0_year_started_2i" name="user[educations_attributes][0][year_started(2i)]" class="date required form-control">

<select id="user_educations_attributes_0_year_started_1i" name="user[educations_attributes][0][year_started(1i)]" class="date required form-control">

CSS:

.date.required.form-control{ 
display: inline-block;
width: 32%;
margin-right: 5px;
}