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