Paste: Custom Form Builder
Author: | Daniel Wanja (modified by Sergio Gómez) |
Mode: | ruby |
Date: | Thu, 26 Feb 2009 07:54:33 |
Plain Text |
class LabelFormBuilder < ActionView::Helpers::FormBuilder
helpers = field_helpers +
%w{date_select datetime_select time_select} +
%w{collection_select select country_select time_zone_select} +
%w{calendar_date_select} -
%w{hidden_field label fields_for}
helpers.each do |name|
define_method(name) do |field, *args|
options = args.extract_options!
label = label(field, options.delete(:label), :class => options.delete(:label_class))
classname = (name == "calendar_date_select" ? "calendardateselect text_field" : name)
case name
when "check_box"
@template.content_tag(:div, @template.content_tag(:p, super + label, :class => classname), :class => "field")
else
@template.content_tag(:div, @template.content_tag(:p, label) + @template.content_tag(:p, super, :class => classname), :class => "field")
end
end
end
end
New Annotation