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/