2014-09-11 25 views
0

大廈自定義配置,我有以下形式軌默認建造的form_for:與simple_form

= form_for @customer do |f| 
    .form-group 
    .col-sm-3 
     = f.label :first_name, "Vorname", class: "control-label" 
    .col-sm-3 
     = f.text_field :first_name, placeholder: "Ihr Vorname", class: 'form-control' 

現在我想建立simple_form配置爲輸入和標籤都相同的類和simple_form_for看起來一樣的form_for。此代碼給我下面的HTML:

  <form accept-charset="UTF-8" action="/portal/sessions" class="new_customer" id="new_customer" method="post"><div style="display:none"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="LeRWJSnYDYvzeW5+KMm9BczbtfHXX6yI6Pg4xLjH2SE=" /></div> <div class='row'> 
       <div class='col-md-12'> 
       <div class='form-group'> 
        <div class='col-sm-3'> 
        <label class="control-label" for="customer_first_name">Vorname</label> 
        </div> 
        <div class='col-sm-3'> 
        <input class="form-control" id="customer_first_name" name="customer[first_name]" placeholder="Ihr Vorname" type="text" /> 
        </div> 
       </div> 
       </div> 
      </div> 
      <input name="commit" type="submit" value="Create Customer" /> 
     </form> 

我試圖寫simple_form配置上我自己的,但它不能正常工作:

config.wrappers :bootstrap, error_class: 'error' do |b| 
    b.use :html5 
    b.use :placeholder 
    b.use :label, class: 'control-label' 
    b.wrapper tag: 'div', class: 'form-group' do |ba| 
     ba.use :input, class: 'form-controlc' 
     ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' } 
     ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } 
    end 
    end 

可能有人可以幫我解決這個問題?

回答

0

答案是:

SimpleForm.setup do |config| 
    config.wrappers :bootstrap, tag: 'div', class: 'control-group', error_class: 'error' do |b| 
    b.use :html5 
    b.use :placeholder 
    b.use :label 
    b.wrapper tag: 'div', class: 'controls' do |ba| 
     ba.use :input 
     ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' } 
     ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } 
    end 
    end 
config.default_wrapper = :bootstrap 
    config.label_class = 'control-label' 
    config.input_class = 'form-control' 
end