Created
May 8, 2013 11:23
-
-
Save stex/5539836 to your computer and use it in GitHub Desktop.
Rails field_error_proc to add an error class to invalid input fields
This file contains hidden or 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
#Overrides the default way how rails marks form fields with errors. | |
#In this version, it only adds the class 'error' to label and element | |
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| | |
if html_tag =~ /<(input|label|textarea|select)/ | |
html_field = Nokogiri::HTML::DocumentFragment.parse(html_tag) | |
html_field.children.add_class 'error' | |
html_field.to_s | |
else | |
html_tag | |
end | |
end |
thanks!
@thedanielhanke is there any other way? Rubocop is complaining...
@mrshortt please provide some more details/infos
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
L8: add .html_safe for newer rails versions