Informant

Updated 9 Oct 2009

Informant is a full-featured form builder for Ruby on Rails which promotes a simple syntax that keeps your views clean. Everything about a field (label, description, error display, etc) is encapsulated in a single method call. Three form layouts are included (Standard, Table, and Simple) and custom layouts can be created easily (write a new class, inherit, and overwrite whatever field templates you want).

All field methods accept an options hash like the standard Rails FormBuilder methods, but with some extra features available. The simplest field takes just an object attribute name:

<%= f.text_field :name %>

The label is inferred from the field name but can be specified manually with the :label option. The second argument to a select field should be an array of options in the same format as used for the default Rails FormBuilder.

Please choose an Italian manufacturer.

<%= f.select :manufacturer,
  Manufacturer.all.map{ |m| [m.name, m.id] },
  :label         => "Brand",
  :include_blank => true,
  :required      => true,
  :description   => "Please choose an Italian manufacturer." %>

In addition to the standard Rails FormBuilder options, you can also specify a label, a required marker, some descriptive text, decoration (such as a spinner for use with AJAX calls), and more. There are also some custom field types, such as radio_buttons (for a set of radio buttons) and habtm_check_boxes:







<%= f.habtm_check_boxes :feature_ids,
  Feature.all.map{ |m| [m.name, m.id] } %>

Note that this method takes an array of choices just like a select field. It also handles the all-unchecked case so you don’t have to deal with it in the controller (if you’ve ever set up has_and_belongs_to_many checkboxes you’re familiar with this problem).

In short, Informant will make your form code shorter and more readable. For complete API documentation see the Informant project at GitHub.