Last active
March 20, 2024 08:33
-
-
Save mec/01d7d5e3fcd56f83d0cc6cbb10edcaa4 to your computer and use it in GitHub Desktop.
Rails default form errors
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
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag| | |
fragment = Nokogiri::HTML.fragment(html_tag) | |
field = fragment.at('input,select,textarea') | |
error_message = instance_tag.error_message.join(", ") | |
html = if field | |
debugger | |
field.add_class("is-danger") | |
html = <<-HTML | |
#{fragment.to_s} | |
<p class="help is-danger">#{error_message}</p> | |
HTML | |
html | |
else | |
html_tag | |
end | |
html.html_safe | |
end | |
# Source: | |
https://github.com/rails/rails/blob/7c68c5210cbc245d778daa7958cab73bc74f4669/actionview/lib/action_view/base.rb#L162 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment