如何使用 twitter bootstrap 和 rails 简单表单创建横向表单

How to create horizontal forms with twitter bootstrap and rails simple form

我正在尝试使用简单形式和 bootstrap 创建水平形式。我已经使用 "rails generate simple_form:install" 安装了 bootstrap。这就是我在 html.erb

中的内容
    <%= simple_form_for(@company, :html => { :class => "form-horizontal" }) do |f| %>
      <div class="form-group">
        <label class="col-md-4 control-label"></label>
        <div class="col-md-4">
           <%= f.input :name %>
</div>
</div>

但表格仍然垂直显示。

simple_form 是一个非常棒的 gem 用于生成 bootstrap 表单。但是,您必须做一些额外的工作才能使其与 Bootstrap 的 form-horizo​​ntal class 一起使用。

README 没有提到这个,但是它是内置的。只需像这样写你的表单声明:

<%= simple_form_for [:admin, @c], html: { class: 'form-horizontal' },wrapper: :horizontal_form do |f| %>

 # ...form...

<% end %>

注意 wrapper 属性。这在 README 中没有描述,我不得不深入研究代码才能弄明白。

希望对您有所帮助!