Skip to content

Instantly share code, notes, and snippets.

@georg
Created August 26, 2009 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georg/175346 to your computer and use it in GitHub Desktop.
Save georg/175346 to your computer and use it in GitHub Desktop.
# The following code lets you define a custom field_error_proc for a template.
# This can be useful for custom form builders when you don't want the default
# field_error_proc behaviour.
#
# class CustomFormBuilder < ActionView::Helpers::FormBuilder
# def initialize(object_name, object, template, options, proc)
# super
# @template.custom_field_error_proc = method(:field_error_proc)
# end
#
# def field_error_proc(html_tag, instance)
# # Do your own custom error wrapping in here.
# end
# end
class ActionView::Base
attr_accessor :custom_field_error_proc
end
class ActionView::Helpers::InstanceTag
alias_method :error_wrapping_without_form_builder, :error_wrapping
def error_wrapping(html_tag, has_error)
if custom_field_error_proc = @template_object.custom_field_error_proc
has_error ? custom_field_error_proc.call(html_tag, self) : html_tag
else
error_wrapping_without_form_builder(html_tag, has_error)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment