Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A simple form builder for Rails apps

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 config
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
Octocat-spinner-32 fomu.gemspec
Octocat-spinner-32 init.rb
README.markdown

Fomu

A simple form builder for Rails apps that adds label, inline error and hint messages automatically with full I18n support.

Usage

Use the form_for helper as usual and fields like this:

<% form_for @user do |f| %>
    <% fieldset "Personal info" do %>
        <%= f.text_field :name %>
        <%= f.text_field :email %>
        <%= f.password_field :password %>
        <%= f.password_field :password_confirmation %>
    <% end %>

    <%= f.submit_or_cancel signin_path, "I already have an account" %>
<% end %>

Available helpers

fieldset

Create a fieldset tag.

<% fieldset "Your account info" do %>
    <!-- all your fields -->
<% end %>

text_field

<%= f.text_field :name %>
<%= f.text_field :name, :label => "Full name" %>
<%= f.text_field :name, :required => true %>
<%= f.text_field :name, :optional => true %>
<%= f.text_field :name, :hint => "Just to identify you" %>

password_field

<%= f.password_field :password %>
<%= f.password_field :password, :label => "Choose your password" %>
<%= f.password_field :password, :required => true %>
<%= f.password_field :password, :required => false %>
<%= f.password_field :password, :hint => "Use letters and numbers, minimum 6 chars" %>

check_box

<%= f.check_box :active %>
<%= f.check_box :active, :label => "This item is visible" %>
<%= f.check_box :active, :required => true %>
<%= f.check_box :active, :required => false %>
<%= f.check_box :active, :hint => "Make this item visible or hidden to other users" %>

check_box_group

Create a check box grouped. Your model attribute should be serialized as Array.

  class User < ActiveRecord::Base
    INTERESTS = %w[ sports music movies ]
    serialize :interests, Array
  end

Then on your form you can write

<%= f.check_box_group :interests, User::INTERESTS %>

The labels are taken from the labels.<MODEL>.<ATTRIBUTE>.<VALUE> scope, so you need to have these scopes in order to translate the values:

  labels.user.interests.sports
  labels.user.interests.music
  labels.user.interests.movies

Otherwise, the humanized method name will be used.

radio_button

<%= f.radio_button :gender %>
<%= f.radio_button :gender, :label => "Boy" %>
<%= f.radio_button :gender, :required => true %>
<%= f.radio_button :gender, :required => false %>
<%= f.radio_button :gender, :hint => "(So we can suggest MEN stuff)" %>

radio_button_group

Create a radio button group.

class User < ActiveRecord::Base
  GENDERS = %w[ male female ]

  serialize :interests, Array
end

<%= f.radio_button_group :gender, User::GENDERS %>

The labels are taken from the labels.<MODEL>.<ATTRIBUTE>.<VALUE> scope like in:

labels.user.gender.male
labels.user.gender.female

Otherwise, the humanized method name will be used.

text_area

<%= f.text_area :about %>
<%= f.text_area :about, :label => "About you" %>
<%= f.text_area :about, :required => true %>
<%= f.text_area :about, :optional => true %>
<%= f.text_area :about, :hint => "This text will be displayed on your profile" %>

select

<%= f.select :status, User::STATUSES %>
<%= f.select :status, User::STATUSES, :label => "User status" %>
<%= f.select :status, User::STATUSES, :required => true %>
<%= f.select :status, User::STATUSES, :optional => true %>
<%= f.select :status, User::STATUSES, :hint => "Set this user status" %>

submit

<%= f.submit %>

Fomu will lookup the following I18n scopes:

labels.<MODEL>.create     # new_record? == true
labels.<MODEL>.update     # new_record? == false
labels.buttons.create     # new_record? == true
labels.buttons.update     # new_record? == false

submit_or_cancel

Create a submit button with a cancel link.

<%= f.submit_or_cancel "/some/path" %>
<%= f.submit_or_cancel users_path %>
<%= f.submit_or_cancel :controller => "users" %>
<%= f.submit_or_cancel "/some/path", "Go back" %>
<%= f.submit_or_cancel users_path, :button => "Send now!" %>
<%= f.submit_or_cancel users_path, :link => "Go back" %>
<%= f.submit_or_cancel users_path, :connector => "or" %>

The submit_or_cancel helper will use the same I18n scopes from submit.

error_messages

Display all error messages

<%= f.error_messages %>

label

<%= f.label :login %>
<%= f.label :login, "Your username" %>
<%= f.label :login, :"custom.18n.scope" %>

Fomu will lookup the following I18n scopes:

labels.<MODEL>.<ATTRIBUTE>
activerecord.attributes.<MODEL>.<ATTRIBUTE>

TO-DO

  • Create some default CSS
  • Add more inputs like country, timezone, date/time, etc.

License

Copyright (c) 2009 Nando Vieira, released under the MIT license

Something went wrong with that request. Please try again.