A handy and flexible table / css form builder
h1. Uber builder
The greatest form builder for Ruby on Rails.
h2. Why is it great?
h2. How do I harness this greatness?
To create a basic form:
<% form_for @user do |f| %>
User details
<% f.table do %>
<% f.manual :label => "Name" do %>
<%= f.text_field :first_name %>
<%= f.text_field :last_name %>
<% end %>
<%= f.text_field :age %>
<% end %>
Billing information
<% f.table do %>
<%= f.text_field :address %>
... etc.
<% end %>
<% end %>
This form, out of the box, will be rendered as a table (with a class of form). To make the labels line up, you’ll want to add some CSS:
table.form td.label {
display:block;
width:200px;
font-weight:bold;
}
You can also render ul / li like so:
<% form_for @user do |f| %>
User details
<% f.ul do %>
...
<% end %>
<% end %>
The ul is rendered with a class of “form”. You’ll need to add css styling to make it work. Good luck with that.
h2. Buy one get one free
If you extract that to a partial, _form.html.erb
, then you could use if as a static view or a form
# render it as a form
<% form_for @user do |f| %>
<%= render :partial => "form", :locals => {:f => f} %>
<% end %>
# render it as static
<% form_for @user, :builder => StaticBuilder do |f| %>
<%= render :partial => "form", :locals => {:f => f} %>
<% end %>
h2. I want to submit a patch
h2. Author
“Tim Harper”:http://tim.theenchanter.com/
h2. Credits
Graeme Mathieson for writing the original “TabularFormBuilder”:http://woss.name/2006/07/13/tabular-formbuilder-for-easily-creating-forms-in-rails/, which I used as a starting point for UberBuilder