Created
February 24, 2010 05:34
-
-
Save laktek/313136 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
#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