BootstrapFormBuilder

A Rails form builder that outputs forms structured for use with the Twitter Bootstrap library. Labels are automatically created, and errors are displayed inline.

BootstrapFormBuilder is built using syntax specific to Ruby 1.9. It will not work on Ruby 1.8.

Usage

The builder conforms generally to the generic Rails form builder API.

<%= bootstrap_form_for @widget do |f| %>
  <%= f.text_field :name %>
  <%= f.collection_select :category_id, Category.all, :id, :name, include_blank: true %>
  <%= f.submit nil, class: 'primary' %>
<% end %>

Labels are automatically created for the field. The label and the input are wrapped inside of divs classed according to Twitter Bootstrap library’s conventions.

The field helpers also accept a block to which it yields the input or select tag. This can be used to decorate the input fields.

<%= f.text_field :price do |input_tag| %>
  <div class="input-append">
    <%= input_tag %>
    <label class="add-on">
      <%= f.check_box :taxable %>
      <span>Sales tax</span>
    </label>
  </div>
<% end %>

More information

twitter.github.com/bootstrap