12

有誰知道如何將類simple_form從'controls'更改爲'form-control'。這是Bootstrap 3中的改變。我知道在config/initializers/simple_form.rb和config/initializers/simple_form_bootstrap.rb中有很多選項,但是我找不到我需要的東西。使用simple_form與引導3

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 
爲「形式組」上面,你可以換出「控制組」中

,但我看不出有什麼辦法改變類的輸入標籤。

+0

您是否嘗試過'ba.use:input,:wrap_with => {:class =>'form-control'}'? – hawk

+0

是的,它將給定的類應用於包含元素的div –

+3

'config.input_class ='form-control''輸入的默認類 – hawk

回答

15

在較新的版本simple_form,有一個新的全球配置,你可以使用:您所需要的寶石版> 3.0.0依賴於軌道> 4.0.0,或即將推出的2.2版本

config.input_class = "form-control" 

。現在,您可以在github上使用v2.2分支。

https://github.com/plataformatec/simple_form/blob/v2.2/CHANGELOG.md

+0

我沒有看到,因爲我沒有運行簡單形式的最新測試版。現在我必須更新到rails 4並更新simpleform並移動到bootstrap 3. haha​​ –

+4

有關如何修復錯誤複選框輸入的任何想法? – caarlos0

+0

http://stackoverflow.com/questions/18571748/rails-4-form-b​​uilder-with-comprehensive-support-for-twitter-bootstrap-3目前還不存在。 –

0

爲什麼不更改默認包裝在simple_form_bootstrap.rb初始化?

config.wrappers :bootstrap, tag: :div, class: "form-group", error_class: "has-error" do |b| 

    # Form extensions 
    b.use :html5 
    b.use :placeholder 

    # Form components 
    b.use :label 
    b.wrapper tag: :div do |ba| 
     ba.use :input 
     ba.use :hint, wrap_with: { tag: :p, class: "help-block" } 
     ba.use :error, wrap_with: { tag: :span, class: "help-block text-danger" } 
    end 
    end 
+0

btw他們現在使用類「form-group」而不是上面的代碼...他們改變了它自beta – mwalsher