0

你能帮我格式化这个simple_form吗?

我正在使用这种形式:

<%= simple_form_for @my_model, :html => { :class => 'form-horizontal'} do |f| %>
<%= f.error_notification %>
    <div class="form-inputs">
      <%= f.input :some_text, :input_html => {:class => "span6", :rows => 2}%>
      <%= f.input :a_description, :input_html => {:class => "span6", :rows => 2}%>  
      <%= f.input :boolean1%>
      <%= f.input :boolean2%>
      <%= f.input :boolean3%>
      <%= f.input :boolean4%>
      <%= f.input :boolean5%>
      <%= f.input :boolean6%>
      <%= f.input :boolean7%>
      <%= f.input :boolean8%>
      <%= f.input :id, :as => :hidden, :input_html => { :value => @my_model.id }%>
  </div>
  <div class="form-actions">
    <%= f.button :submit, :class => 'btn-primary' %>
    <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
                special_path, :class => 'btn' %>
  </div>
<% end %>

我想将布尔值显示为两列复选框,每列垂直堆叠有 4 个复选框。

就像是

Some text:      [input]
A description:  [input] 
                bool1    bool5
                bool2    bool6
                bool3    bool7
                bool4    bool8

我在这里克隆了 git 存储库http://simple-form-b​​ootstrap.plataformatec.com.br/articles/new,查看代码,运行它,我发现它有效。
但是......它适用于存储在字符串中的一系列复选框选项。我有一个具有 8 个布尔值的模型,无法理解如何使用 rails、css、twitter-bootstrap 和 simple_form 将它们正确分组。

我已经阅读了这篇 SO 帖子:将所有输入字段放在同一行
......还有这个:在 Rails 中使用 simple_form、nested_form 和 Twitter Bootstrap 添加控件

...但它们似乎不适合我的特殊情况,我没有想法尝试。

请尝试将您的答案集中在一个特定的代码示例上,该示例显示如何以某种分组方式为单个布尔值布局复选框。

提前致谢!

4

1 回答 1

1

我过去只使用普通的网格控件制作了多列引导表单。在您的情况下,类似于:

<div class="form-inputs">
  ...
  <div class="row">
    <div class="span6">
      <%= f.input :boolean1 %>
      <%= f.input :boolean2 %>
      ...
    </div>
    <div class="span6">
      <%= f.input :boolean5 %>
      <%= f.input :boolean6 %>
      ...
    </div>
  </div>
  ...
</div>

然后,您可以使用不同的spanoffset类来调整这些列。

于 2012-10-23T23:21:16.523 回答