A plugin that handles form errors a more gracefully than the Rails default
This plugin adds form builder (block-style) helper methods that handle
errors on fields in a cleaner way than the Rails default.
New helper methods are:
When validations cause errors on a model’s fields, LabeledFormWithErrorsBuilder
wraps the generated elements using this Proc (which you can customize in init.rb)
ActionView::Base.field_error_proc = Proc.new{ |input_or_label, instance| “<span class=“form_error”>#{input_or_label}” }
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 => /[1]$/, :allow_nil => true, :message => “must be m or f”
end
<% labeled_form_for(@person) do |f| %>
Generates:
Copyright © 2008 Cameron Walters, released under the MIT license
mf ↩︎