问题
The following command integrates simple_form with 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|
===============================================================================
But I want to integrate my simple_form with bootstrap 3. What is the command used for this?
回答1:
It's a little tricky to get Bootstrap 3 to work properly with SimpleForm, but the instructions on this page work pretty well for me, almost verbatim:
Using Twitter Bootstrap 3 with simple_form
(I'm using Rails 3.2, but I think they will work equally well for Rails 4. YMMV.)
Here's the key points:
- Modify the
simple_form.rb
initializer by addingcol-lg-2
to theconfig.label_class
declaration - Modify the
simple_form_bootstrap.rb
initializer by changing all instances (3) of "control-group" to "form-group", and all instances (3) of "control" to "col-lg-10" - Add an additional initializer (load before your existing simple_form initializers!) to modify classes on the inputs themselves.
And, of course, don't forget to restart your rails server to pickup the changes.
来源:https://stackoverflow.com/questions/23784830/bootstrap3-and-simple-form