Skip to content

Instantly share code, notes, and snippets.

@rorlab
Created October 4, 2012 10:51
Show Gist options
  • Save rorlab/3832924 to your computer and use it in GitHub Desktop.
Save rorlab/3832924 to your computer and use it in GitHub Desktop.
Custom field_error_proc
# Custom field_error_proc
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
errors = Array(instance.error_message).join(', ')
if html_tag =~ /^<label/
if html_tag !~ /^<label(?:\s+.*)*(\s+alt="(?:checkbox|hidden)")(?:\s+.*)*\s*/
%(#{html_tag}).html_safe
else
%(#{html_tag}<span class="validation-error">&nbsp;#{errors}</span>).html_safe
end
else
if html_tag =~ /(<input(?:\s+.*)*(\s+type="(?:checkbox|hidden)")(?:\s+.*)*\s*\/>)/
%(#{html_tag}).html_safe
else
%(#{html_tag}<span class="validation-error">&nbsp;#{errors}</span>).html_safe
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment