使用带引导程序3的simple_form

时间:2013-08-23 12:51:43

标签: ruby-on-rails twitter-bootstrap simple-form twitter-bootstrap-3

有没有人知道如何将simple_form使用的类从'controls'更改为'form-control'。这是Bootstrap 3中的一个更改。我知道config / initializers / simple_form.rb和config / initializers / simple_form_bootstrap.rb中有很多选项,但我找不到我需要的内容。

  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

在上面你可以将'control-group'替换为'form-group',但我认为无法改变输入标签的类。

2 个答案:

答案 0 :(得分:15)

在较新的simple_form版本中,您可以使用新的全局配置:

config.input_class = "form-control"

你需要宝石版> 3.0.0,这取决于rails> 4.0.0,或即将推出的2.2版本。您现在可以在github上使用v2.2分支。

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

答案 1 :(得分: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