15

我已经将bootstrap更新为版本3.除了由simple_form gem生成的表单之外,一切正常。我不知道我怎么能把这两者结合在一起。我在github项目资源库中找不到任何有用的建议。那么,有没有人有我的解决方案?simple_form与bootstrap的集成3

回答

1

您需要通过在config/initializers中创建初始化程序并填充下面的内容来创建引导程序特定的simple_form设置。

# Use this setup block to configure all options available in SimpleForm. 
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.wrappers :prepend, 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 |input| 
     input.wrapper tag: 'div', class: 'input-prepend' do |prepend| 
     prepend.use :input 
     end 
     input.use :hint, wrap_with: { tag: 'span', class: 'help-block' } 
     input.use :error, wrap_with: { tag: 'span', class: 'help-inline' } 
    end 
    end 

    config.wrappers :append, 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 |input| 
     input.wrapper tag: 'div', class: 'input-append' do |append| 
     append.use :input 
     end 
     input.use :hint, wrap_with: { tag: 'span', class: 'help-block' } 
     input.use :error, wrap_with: { tag: 'span', class: 'help-inline' } 
    end 
    end 

    # Wrappers for forms and inputs using the Twitter Bootstrap toolkit. 
    # Check the Bootstrap docs (http://twitter.github.com/bootstrap) 
    # to learn about the different styles for forms and inputs, 
    # buttons and other elements. 
    config.default_wrapper = :bootstrap 
end 
+1

这是自举2 – Edward

0

好消息大家:为2014年4月,Bootstrap 3 integration is more fully supported,在新版本提供了额外包装的。

我们刚刚发布了简单的表单3.1.0.rc1的支持来引导3. 为了能够,我们铲平了包装API,使其更具可扩展 ,并允许开发者直接进行配置,而不是依靠全球的国家。 经过这样的改进,这是非常容易简单形式配置更改为 工作,引导3

您可以通过一个示例应用在这里看到工作中的新功能:http://simple-form-bootstrap.plataformatec.com.br/