Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Oversan/7641636 to your computer and use it in GitHub Desktop.
Save Oversan/7641636 to your computer and use it in GitHub Desktop.
# put this in config/initializer/fields_with_errors.rb
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
if html_tag =~ /<(input|label|textarea|select)/
error_class = 'error'
doc = Nokogiri::XML(html_tag)
doc.children.each do |field|
unless field['type'] == 'hidden'
unless field['class'] =~ /\berror\b/
field['class'] = "#{field['class']} error".strip
end
end
end
doc.to_html.html_safe
else
html_tag
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment