Skip to content

Instantly share code, notes, and snippets.

View kcore's full-sized avatar

Kiran Narasareddy kcore

View GitHub Profile
@andreimoment
andreimoment / customize_error.rb
Last active July 18, 2020 13:54 — forked from telwell/customize_error.rb
Customize Field Errors with Rails 5 and Bootstrap
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = ''
form_fields = %w(textarea input select)
tag_elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, " + form_fields.join(', ')
tag_elements.each do |e|
if e.node_name.eql? 'label'
html = %(#{e}).html_safe
elsif form_fields.include? e.node_name