Skip to content

Instantly share code, notes, and snippets.

@Soraph
Created October 29, 2013 09:09
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 Soraph/7211324 to your computer and use it in GitHub Desktop.
Save Soraph/7211324 to your computer and use it in GitHub Desktop.
field_error_proc override to add the "has-error" class
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
if html_tag.match(/class=(\'|\")([\w\s\d]*?)\1/i)
html_tag.gsub(/class=(\'|\")([\w\s\d]*?)\1/i, 'class="\2 has-error"')
else
html_tag.gsub(/\<[\w]+/i, '\0 class="has-error"')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment