class ComfyBlog::FormBuilder < ActionView::Helpers::FormBuilder helpers = field_helpers - %w(hidden_field fields_for) + %w(select) helpers.each do |name| class_eval %Q^ def #{name}(field, *args) options = args.extract_options! args << options return super if options.delete(:disable_builder) default_field('#{name}', field, options){ super } end ^ end def default_field(type, field, options = {}, &block) errors = if object.respond_to?(:errors) && object.errors[field].present? "
#{[object.errors[field]].flatten.first}
" end if desc = options.delete(:desc) desc = "
#{desc}
" end %(
#{label_for(field, options)}
#{yield}
#{desc} #{errors}
).html_safe end def label_for(field, options) label = options.delete(:label) || field.to_s.titleize.capitalize "".html_safe end def simple_field(label = nil, content = nil, options = {}, &block) content ||= @template.capture(&block) if block_given? %(
#{label}
#{content}
).html_safe end end