BootstrapForm is a form builder that makes it super easy to integrate Twitter Bootstrap-style forms into your Rails App.
- Ruby 1.9+
- Rails 3, 4
- Twitter Bootstrap 3.0+
Add it to your Gemfile:
gem 'bootstrap_form'
Then:
bundle
Add this line to app/assets/stylesheets/application.css.scss:
/*
*= require bootstrap_form
*/
To get started, just use the BootstrapForm form helper. Here's an example:
<%= bootstrap_form_for(@user) do |f| %>
<%= f.text_field :name %>
<%= f.email_field :email %>
<%= f.password_field :password %>
<%= f.submit "Create My Account" %>
<% end %>
This gem wraps the following Rails form helpers:
- text_field
- password_field
- text_area
- file_field
- number_field
- email_field
- telephone_field / phone_field
- url_field
- select
- collection_select
- date_select
- time_select
- datetime_select
- check_box
- radio_button
By default, your forms will stack labels on top of controls and your controls will grow to 100% of the available width.
To use a inline-style form, use the style: :inline
option. To hide labels, use
the sr-only
class, which keeps your forms accessible for those using Screen
Readers.
<%= bootstrap_form_for(@user, style: :inline) do |f| %>
<%= f.email_field :email, label_class: "sr-only" %>
<%= f.password_field :password, label_class: "sr-only" %>
<%= f.check_box :terms, label: "Remember Me" %>
<%= f.submit "Create My Account" %>
<% end %>
To use a horizontal-style form with labels to the left of the inputs,
use the style: :horizontal
option. You should specify both left
and
right
css classes as well (they default to col-sm-2
and col-sm-10
).
<%= bootstrap_form_for(@user, style: :horizontal, left: "col-sm-2", right: "col-sm-10") do |f| %>
<%= f.email_field :email %>
<%= f.password_field :password %>
<%= f.form_group do %>
<%= f.submit "Create My Account" %>
<% end %>
<% end %>
http://www.codetriage.com/potenza/bootstrap_form
https://github.com/potenza/bootstrap_form/graphs/contributors
MIT License. Copyright 2012-2013 Stephen Potenza (https://github.com/potenza)