Skip to content

Instantly share code, notes, and snippets.

@chryoung
Created April 5, 2022 13:24
Show Gist options
  • Save chryoung/210780a260ed378940739f6993c0159b to your computer and use it in GitHub Desktop.
Save chryoung/210780a260ed378940739f6993c0159b to your computer and use it in GitHub Desktop.
Ruby on Rails: Customize field_error_proc to remove div.field_with_errors wrapper
# Save this file to your_rails_project/config/initializers/
# With this code, a form-input-error class can be applied to the input so that it can be styled by tailwindcss or CSS.
# See the original definition on
# https://github.com/rails/rails/blob/c5bf2b4736f2ddafbc477af5b9478dd7143e5466/actionview/lib/action_view/base.rb#L145
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
if html_tag.start_with? '<input'
html_tag.gsub(/class="[^"]+"/, 'class="form-input-error"').html_safe
else
html_tag
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment