Bootstrap3和简单的形式

时间:2014-05-21 13:34:52

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

以下命令将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 集成。这个命令用的是什么?

1 个答案:

答案 0 :(得分:3)

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

Using Twitter Bootstrap 3 with simple_form

(我正在使用Rails 3.2,但我认为它们对Rails 4同样有效.YMMV。)

以下是关键点:

  1. 通过将simple_form.rb添加到col-lg-2声明
  2. 来修改config.label_class初始值设定项
  3. 修改simple_form_bootstrap.rb初始化程序,方法是将“control-group”的所有实例(3)更改为“form-group”,并将“control”的所有实例(3)更改为“col-lg-10”< / LI>
  4. 添加一个额外的初始化程序(在现有的simple_form初始化程序之前加载!)来修改输入本身的类。
  5. 当然,不要忘记重启rails服务器以获取更改。