2012-10-23 23 views
0

您能否幫助我設置這個simple_form的格式?使用css,twitter-bootstrap和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-bootstrap.plataformatec.com.br/articles/new,看了看代碼,運行它,我看到它的工作原理。
但是...它適用於存儲在字符串中的一系列複選框選項。我有一個具有8個布爾值的模型,並且無法理解如何在使用rails,css,twitter-bootstrap和simple_form的表單中將它們正確分組。

我讀過這個SO帖子:Make all input fields on the same line
...這一個:Adding controls inline with simple_form, nested_form and Twitter Bootstrap in Rails

...但他們似乎並不適合我的特殊情況,我的想法去嘗試。

請嘗試將您的答案關注於一個特定的代碼示例,該示例演示如何以某種分組方式佈局各個布爾值的複選框。

在此先感謝!

回答

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類調​​整不過你想要的那些列。

+0

哇。如此基礎。效果很好。謝謝。想想我到這裏去了多遠的地方有點尷尬。 –