【问题标题】:Bootstrap3 and simple formBootstrap3 和简单的形式
【发布时间】:2014-05-21 13:34:52
【问题描述】:

以下命令将 simple_form 与 twitter-bootstrap 集成

$ rails g simple_form:install --bootstrap

  identical  config/initializers/simple_form.rb

  create  config/initializers/simple_form_bootstrap.rb

  exist  config/locales

  identical  config/locales/simple_form.en.yml

  identical  lib/templates/erb/scaffold/_form.html.erb
===============================================================================

  Be sure to have a copy of the Bootstrap stylesheet available on your
  application, you can get it on http://twitter.github.com/bootstrap.

  Inside your views, use the 'simple_form_for' with one of the Bootstrap form
  classes, '.form-horizontal', '.form-inline', '.form-search' or
  '.form-vertical', as the following:

    = simple_form_for(@user, html: {class: 'form-horizontal' }) do |form|

===============================================================================

但我想将我的 simple_form 与 bootstrap 3 集成。用于此的命令是什么?

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap ruby-on-rails-4 simple-form bootstrap-sass


    【解决方案1】:

    让 Bootstrap 3 与 SimpleForm 一起正常工作有点棘手,但这个页面上的说明对我来说效果很好,几乎是逐字逐句:

    Using Twitter Bootstrap 3 with simple_form

    (我使用的是 Rails 3.2,但我认为它们同样适用于 Rails 4。YMMV。)

    以下是重点:

    1. 通过将col-lg-2 添加到config.label_class 声明来修改simple_form.rb 初始化程序
    2. 修改 simple_form_bootstrap.rb 初始化程序,将“control-group”的所有实例 (3) 更改为“form-group”,并将“control”的所有实例 (3) 更改为“col-lg-10”
    3. 添加一个额外的初始化程序(在您现有的 simple_form 初始化程序之前加载!)以修改输入本身的类。

    当然,不要忘记重新启动 Rails 服务器以获取更改。

    【讨论】:

    • #2) 应该改成col-lg-10的不是control,而是controls。以防万一有人想知道。
    • @gwho 这只是在article I mentioned 之后。在“config/initializers/remove-this-sf_bs3_inputs.rb”中创建一个新文件。文件名无关紧要,但初始化程序是按字母顺序加载的,所以给它一个名字,让它出现在“simple_form_bootstrap.rb”之前。复制文章底部以inputs = %w[...开头的内容即可
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 2015-07-05
    相关资源
    最近更新 更多