Created
August 26, 2009 06:01
-
-
Save georg/175346 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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