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} # Don't decorate these

  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))
      # lo siguiente es una chapuza para evitar los estilos del dichoso calendar_date_select
      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

Summary:
Author:
Mode:
Body: