public
Description: A handy and flexible table / css form builder
Homepage: http://code.google.com/p/uber-builder/
Clone URL: git://github.com/timcharper/uber-builder.git
timcharper (author)
Wed Oct 01 12:09:54 -0700 2008
commit  13514b167796f2edf00acb55a32c558b5ed1238a
tree    6551f16f3b14811b9dee92bad44b914d8ba4d545
parent  e53c27c4219bf8a4a481f7f15edc24b656343a8d
name age message
file README.textile Wed Oct 01 12:09:54 -0700 2008 fixed README [timcharper]
file init.rb Sat Sep 27 14:39:13 -0700 2008 added div layout [timcharper]
directory lib/ Sat Sep 27 14:39:19 -0700 2008 converted line endings [timcharper]
directory spec/ Sat Sep 27 14:39:13 -0700 2008 added div layout [timcharper]
README.textile

Uber builder

The greatest form builder for Ruby on Rails.

Why is it great?

  • Tabular forms
  • ul / li css forms
  • Easily extensible
  • Comes with a few useful extensions already
  • Comes with a FormBuilder compliant StaticBuilder to render any form built with it as static.

How do I harness this greatness?

To create a basic form:

<% form_for @user do |f| %>
  <h2>User details</h2>
  <% f.table do %>
    <% f.manual :label => "Name" do %>
      <%= f.text_field :first_name %>
      <%= f.text_field :last_name %>
    <% end %>
    <%= f.text_field :age %>
  <% end %>

  <h2>Billing information</h2>
  <% 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| %>
  <h2>User details</h2>
  <% 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.

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 %>

I want to submit a patch

  1. Fork Uber-Builder
  2. Make your modification
  3. Add tests!
  4. Make sure all existing tests pass
  5. Send me a pull request on github

Author

Tim Harper

Credits

Graeme Mathieson for writing the original TabularFormBuilder, which I used as a starting point for UberBuilder