Skip to content

Instantly share code, notes, and snippets.

@laktek
Created February 24, 2010 05:34
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 laktek/313136 to your computer and use it in GitHub Desktop.
Save laktek/313136 to your computer and use it in GitHub Desktop.
#Changing the default behavior of field Errors
# config/initializers/field_errors.rb
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
msg = instance.error_message
if html_tag =~ /<(input|textarea|select)[^>]+class=/
class_attribute = html_tag =~ /class=['"]/
html_tag.insert(class_attribute + 7, "error")
elsif html_tag =~ /<(input|textarea|select)/
first_whitespace = html_tag =~ /\s/
html_tag[first_whitespace] = " class='error' "
end
html_tag
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment