Another Rails Plugin: LabeledFormWithErrors
Today I released my second plugin for Rails.
It’s pretty simple. It’s a set of 4 helper methods, based on the form builder that comes with Rails 2.0+ that provides you a sane way to present the error messages from your Model validations on form labels. That’s enough tell, on with the show!
# app/models/person.rb
class Person < ActiveRecord::Base
validates_presence_of :name, :age, :gender
validates_numericality_of :age, :message => "must be a number"
validates_length_of :gender, :is => 1,
:message => "must be exactly 1 character"
validates_format_of :gender, :with => /^[mf]$/,
:message => "must be m or f"
end
After submitting with all fields blank, the example scaffold form looks like this :

That’s pretty much it. As Jamis says, “never use a plugin you would not be able to write yourself.”
You can clone the plugin repo using git from
git://github.com/cee-dub/labeledformwitherrors.git
or download the tarball here