seyhunak/twitter-bootstrap-rails — Issue #42: Bootstrap Form Builder
Author: GMFlash
Created: 2012-01-28 17:48:34+00:00
State: open

I wrote a bootstrap_form_for builder that outputs HTML for use with Bootstrap 2.0's .form-horizontal or .form-vertical styles.

https://gist.github.com/1695087

It follows Bootstrap's convention of adding the .error class to the .control-group fieldset and overrides Rail's default error wrapping behavior. It does not conflict with ActionView::Base.field_error_proc so non-bootstrap forms function normally.

This gem seems like a good home for a bootstrap form builder so I thought I would share what I have if you wish to use it as a starting point. It obviously is very basic and needs refinement but it gets the job done.

```
<%= bootstrap_form_for @user, html: {class: 'form-horizontal'} do |f| %>

Create an Account

<%= f.control_group :email do %>
<%= f.email_field :email %>
<% end %>

<%= f.control_group :password do %>
<%= f.text_field :password %>

Must be at least 6 characters

<% end %>

<%= f.control_group :full_name do %>
<%= f.text_field :full_name %>
<% end %>

<%= field_set_tag nil, class: 'form-actions' do %>
<%= button_tag 'Create account', type: 'submit', class: 'btn primary' %>
<%= link_to 'Cancel', root_path %>
<% end %>
<% end %>
```